Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-05-28
6
Medium Priority
?
1,354 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 1800 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 200 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

719 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