I am running a validation function and i call a msgbox at the end to let the user know their information was valid.
The problem is that the words are left justified, besides adding spaces to the front of the msg box is there a better way to center the text?
The problem is that the words are left justified, besides adding spaces to the front of the msg box is there a better way to center the text?
Code:
Public Function ValidatePW(password As String, Username As String, DomainName As String) As Boolean
' Start by retrieving the user's name
Dim lpBuffer As String, nSize As Long
Dim rv As Long, usrName As String
Dim hToken As Long
' Initialise an empty buffer, 10 characters long (long enough for most user names)
lpBuffer = String(10, Chr(0))
Do
nSize = Len(lpBuffer)
rv = Getusername(lpBuffer, nSize)
If rv = 0 Then
' The function probably failed due to the buffer being too small
' nSize holds the required size
lpBuffer = String(nSize, Chr(0)) ' Resize buffer to accomodate big name
End If
Loop Until rv <> 0
' Extract user name from buffer
usrName = Left(lpBuffer, nSize - 1)
If usrName <> Username Then
MsgBox "Unable to login your user name is incorrect"
Exit Function
End If
If Domain() <> DomainName Then
MsgBox "Unable to login your user Domain name is incorrect"
Exit Function
End If
' Now validate the password
rv = LogonUser(usrName, vbNullString, password, LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, hToken)
If rv <> 0 Then
' Password validated successfully
MsgBox "Your Password is valid"
DoCmd.Close acForm, "frmLogin", acSaveNo
DoCmd.OpenForm "frmRiskSwitch", acNormal
Else
' Username and password failed validation
MsgBox "Your Password is Invalid"
End If
End Function
Comment