troubleshooting Question

StrPtr doesn't compile in MS Access 2013 64 bit

Avatar of David Smithstein
David SmithsteinFlag for United States of America asked on
VBAMicrosoft Access
3 Comments1 Solution1733 ViewsLast Modified:
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
Else
   GoTo PasswordFail
End If

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), _
         StrPtr(newpw))
         
     Select Case NetRet
         Case NERR_SUCCESS
        
                WindowPassword = True
         Case INVALID_PASSWORD
          
                WindowPassword = False
          
         Case ACCESS_DENIED
                WindowPassword = False
           
     End Select
     
 End Function

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...

Thanks!
David
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros