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 ApplySignatureElse GoTo PasswordFailEnd 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...
StrPtr String converter. Returns a LongPtr on 64-bit versions, and a Long on 32-bit versions (4 bytes).