Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

MS Access on 32 vs  64 bit and VBA7

Posted on 2016-08-17
4
Medium Priority
?
270 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 58

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 1400 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 28

Assisted Solution

by:MacroShadow
MacroShadow earned 600 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 58
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

885 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