Solved

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

Posted on 2013-05-28
6
1,274 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
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…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

856 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