Solved

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

Posted on 2013-05-28
6
1,307 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 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

752 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