Solved

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

Posted on 2013-05-28
6
1,328 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 58

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 58
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

627 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