Solved

MS Access on 32 vs  64 bit and VBA7

Posted on 2016-08-17
4
139 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
[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
  • 2
4 Comments
 
LVL 57

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 350 total points
ID: 41760098
<<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 27

Assisted Solution

by:MacroShadow
MacroShadow earned 150 total points
ID: 41760189
Your problem has nothing to do with conditional compilation.
The problem is that you named the module  with this code apiGetUserName.
0
 
LVL 57
ID: 41760205
<<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
ID: 41761127
Thank you a lot.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
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.

761 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