Solved

Office32 bit to 64 bit and running on Access2007, Win32 bit OS

Posted on 2013-05-28
6
1,225 Views
Last Modified: 2013-12-03
I've been researching various threads and have to say, been a bit confused.

I developed an app on Office 2007 using an Access2003 database.
I then upgraded to Office 2010, but still kept the DB in Access 2003 format.

I use many API's like this one:
Public Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long

I loaded my app on a '64 Bit Office' PC and the api call failed. (Compile Error)
I fixed the api call as below .

#If Win64 Then
Public Declare PtrSafe Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As LongLong) As LongLong
#Else
Public Declare PtrSafe Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
#End If


All worked fine for both Office 32Bit and Office 64 bit running on '64Bit Windows 7'.

I then stepped back a bit and ran the app on a '32Bit Windows 7' machine, Using Access 2007. Now the API that I just fixed fails to compile.

What do I need to do to have it compile? It seems it can't compile 'PtrSafe'.  Is it the compiler that cannot compile 'PtrSafe'  on a Office 2007, 32 bit machine?

I also want this to run on XP, which I expect will be fine once I figure out what's up with this problem.

John
0
Comment
Question by:askolits
  • 3
  • 2
6 Comments
 
LVL 12

Accepted Solution

by:
pdebaets earned 450 total points
ID: 39203657
The following should work in all versions of Access:

#if vba7 then
    Public Declare PtrSafe Function GetComputerName Lib "kernel32" _ 
        Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
#else
    Public Declare Function GetComputerName Lib "kernel32" _
        Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
#end if

Open in new window

0
 

Author Comment

by:askolits
ID: 39204171
Peter,

OK, so here's my question, it seems when I converted my original DB over to 32Bit office, I used "#If Win64". When using that method, I also had to prefix each  'Function' with "PtrSafe" for both 32 and 64bit API calls.

But if I use your method, I'll then have to use that prefix only within the "#if vba7 " section and remove it within the "#Else" section.

Even though, while running 32Bit Win7,  and the lines within the  "#if vba7 " section are highlighted red, I should be OK.

Correct?

John
0
 
LVL 57

Assisted Solution

by:Jim Dettman (Microsoft MVP/ EE MVE)
Jim Dettman (Microsoft MVP/ EE MVE) earned 50 total points
ID: 39204398
John,

<<OK, so here's my question, it seems when I converted my original DB over to 32Bit office, I used "#If Win64". When using that method, I also had to prefix each  'Function' with "PtrSafe" for both 32 and 64bit API calls.>>

The catch there is that PtrSafe only works in VBA 7 (Office 2010).   It does not work in prior versions.  Also, there are differences in some API calls between 32 and 64 bits.  In those cases, you need to use the Win64 constant.

Not sure you've seen this or not, but look at the section "Application Programming Interface Compatibility"  here:

Compatibility Between the 32-bit and 64-bit Versions of Office 2010
http://msdn.microsoft.com/en-us/library/office/ee691831(v=office.14).aspx

 and pay close attention to the last part of that section and the last example given.   Note the difference in the API call to the math lib between 32 and 64 bit.

Jim.
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:askolits
ID: 39204482
Jim.
"The catch there is that PtrSafe only works in VBA 7 (Office 2010)."

Yea, I see that. It highlights those API calls it in Red, but I guess as long as I use #vba7, the compiler ignores the error.

I think I finished converting from "#if Win64" to  #if vba7". I'll wait to see what breaks when running under all the different OS and Access combinations. Then I'll know what API I need to change to handle 64. Hopefully I'll know today.

Thanks for the compatibility link. I have seen it before but only breezed through it. I'll spend more time on it.

(Gee, I wish MS didn't make this so difficult.)
0
 
LVL 57
ID: 39204519
<<Yea, I see that. It highlights those API calls it in Red, but I guess as long as I use #vba7, the compiler ignores the error.>>

 That's what you want to do.

 and for the cases where the actual API call is different between 32 and 64 bit, you want to use the Win64 constant.

Jim.
0
 

Author Comment

by:askolits
ID: 39204527
Got it. Thanks.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now