Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MS Access on 32 vs  64 bit and VBA7

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

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
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…

721 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