Solved

MS Access on 32 vs  64 bit and VBA7

Posted on 2016-08-17
4
64 Views
Last Modified: 2016-08-18
I have this part of code to make my Access 2003 32 bit application to work on 64 bit and MS access 2010.

Option Explicit


#If Win64 Then
 
    Declare PtrSafe Function apiGetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As LongLong) As LongLong
#Else
 
    Declare Function apiGetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
#End If

#If VBA7 Then
 
    Private Declare PtrSafe Function apiGetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
#Else
 
    Private Declare Function apiGetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
#End If


I am getting error in part :

#If VBA7 Then
 
    Private Declare PtrSafe Function apiGetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long <<< error line.
Error :Compile Error:
Ambiguous name detected apiGetUserName

How to get rid of this and get this function work in 32 and 64 as on new and old Access.?
0
Comment
Question by:Taras
  • 2
4 Comments
 
LVL 57

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 350 total points
Comment Utility
<<How to get rid of this and get this function work in 32 and 64 as on new and old Access.?>>

#If Win64  tells you if Office is running in 32 bit or 64 bit mode.

#If VBA7 tells you if your running Office 2010 or higher (32 or 64 bit).

From:

https://msdn.microsoft.com/en-us/library/ee691831(office.14).aspx#odc_office2010_Compatibility32bit64bit_Comparing32BitSystemsto64BitSystems

"As stated earlier, there are two new conditional compilation constants: VBA7 and Win64. To ensure backward compatibility with previous versions of Microsoft Office, you use the VBA7 constant (this is the more typical case) to prevent 64-bit code from being used in the earlier version of Microsoft Office. For code that is different between the 32-bit version and the 64-bit version, such as calling a math API which uses LongLong for its 64-bit version and Long for its 32-bit version, you use the Win64 constant. The following code demonstrates the use of these two constants."

 So in this case, unless that call is different between 32 and 64 bit, then it should not be in the Win64 section.

Here's a list of all the calls that were modified for 64 bit:
http://msdn.microsoft.com/en-us/library/aa383663(VS.85).aspx

also:

http://www.microsoft.com/download/en/confirmation.aspx?displaylang=en&id=9970

Jim.
0
 
LVL 26

Assisted Solution

by:MacroShadow
MacroShadow earned 150 total points
Comment Utility
Your problem has nothing to do with conditional compilation.
The problem is that you named the module  with this code apiGetUserName.
0
 
LVL 57

Expert Comment

by:Jim Dettman (Microsoft MVP/ EE MVE)
Comment Utility
<<Your problem has nothing to do with conditional compilation.>>

  He's got the same call declared twice and right now, he's running 64 bit in 2010 or higher, so both constants are true.

Jim.
1
 

Author Closing Comment

by:Taras
Comment Utility
Thank you a lot.
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

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
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.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

772 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

9 Experts available now in Live!

Get 1:1 Help Now