We help IT Professionals succeed at work.
Get Started

StrPtr doesn't compile in MS Access 2013 64 bit

David Smithstein
Last Modified: 2017-03-28
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...

Watch Question
President / Owner
Most Valuable Expert 2017
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE