Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Access 2003 - PtrSafe

Access 2003 - PtrSafe

Access 2003 - PtrSafe

I need to alter an Access 2003 system (Running with Access 2000 File Format) to run on a mix of machines and I am by no means an Access expert.

All was fine with my altering the system in Access 2003 on an XP machine and installing it on the customers machines remotely (They are a considerable distance away) until they started to upgrade their machines and their software.

There is now a mix of 32 and 64 bit machines running Access 2003 and the latest version of Access.

On one particular machine when the Access system is started it comes up saying that the code in the project should be updated, saying that the Declare statements should have the PtrSafe attribute applied.

I have looked through the system and there is only one Declare statement in the software:-
Private Declare Sub Sleep Lib "kernel32" (ByVal lngMilliSeconds As Long)
but there are many Private Function statements in the Modules.

I have altered the Declare statement above to:-
#If win64 then
Private Declare Sub Sleep Lib "kernel32" (ByVal lngMilliSeconds As Long)
Private Declare Sub Sleep Lib "kernel32" (ByVal lngMilliSeconds As Long)
#end if
which runs successfully on my machine, but when I put the PrtSafe attribute into the Win64 Declare statement I get an error.

Can anyone tell me if the PrtSafe statement is valid in Access 2003, and if it is how would I use it in the Declare statement above, or if it is not how could I achieve what I am trying to do!
Also, is it just the Declare statement that needs altering or do all the Private Function statements need altering as well?

Thanks for helping!

RE: Access 2003 - PtrSafe

PtrSafe was introduced with VBA7, which first appeared in Office (and therefore Access) 2010

So rather than

#if Win64 then

you might like to consider

#If VBA7 then

RE: Access 2003 - PtrSafe

I have successfully used this code from Daniel Pineault's web page.

CODE --> vba

#If VBA7 And Win64 Then
    'x64 Declarations
    Private Declare PtrSafe Function apiGetUserName Lib "advapi32.dll" Alias _
            "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    'x32 Declaration
    Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
            "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
#End If 

Hook'D on Access
MS Access MVP 2001-2016

RE: Access 2003 - PtrSafe

Thanks DHookom,
Your suggestion worked!

RE: Access 2003 - PtrSafe

You might like to give Duane a purple star via clicking "great post"

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close