Avatar of David Smithstein
David Smithstein
Flag for United States of America asked on

StrPtr doesn't compile in MS Access 2013 64 bit

I need some help adjusting some code to compile in both 64 and 32 bit Office environments.  The follow code works perfectly in the 32 bit world but not 64.  I figured out that I needed to PtrSafe all my declare statements, but this isn't in a declare statement so I'm not sure what I'm doing here.

The section of code is just for reference to show how the WindowsPassword function is being used.
If WindowPassword(Forms![Frm_ElectronicSignature]![Password2], Forms![Frm_ElectronicSignature]![Password2]) = True Then
    GoTo ApplySignature
   GoTo PasswordFail
End If

Open in new window

This next section doesn't compile in 64 bit MS Access 2013, and I get the message "Compile Error - Type Mismatch" with StrPtr highlighted.

Public Function WindowPassword( _
     ByVal oldpw As String, _
     ByVal newpw As String, _
     Optional ByVal Username As String = vbNullString) As Boolean
     Dim NetRet As Long
     'If UserName not specified, _
         defaults to current user logged on.
    NetRet = NetUserChangePassword(0&, _
         StrPtr(Username), _
         StrPtr(oldpw), _
     Select Case NetRet
         Case NERR_SUCCESS
                WindowPassword = True
                WindowPassword = False
         Case ACCESS_DENIED
                WindowPassword = False
     End Select
 End Function

Open in new window

I did enough research to get the idea that between 32 bit and 64 bit apps there is some issue about going between ANSI and UNICODE and something about a variable or a pointer overwriting the address next to it if it gets a 64 bit package for only a 32 bit address...or something like that....the reason behind "PtrSafe" no doubt.  Enough to know I'd better ask someone who knows more about it than I do.

Any help getting this to work in both environments would be deeply appreciated...

VBAMicrosoft Access

Avatar of undefined
Last Comment
David Smithstein

8/22/2022 - Mon
John Tsioumpris

StrPrt on 64bit systems behaves  different then  x86

StrPtr String converter. Returns a LongPtr on 64-bit versions, and a Long on 32-bit versions (4 bytes).
Jim Dettman (EE MVE)

View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
David Smithstein

Thanks Jim, I appreciate the references, I guess I need to invest the time to make this a good solution, and not just a quick one.  :-)
Your help has saved me hundreds of hours of internet surfing.