LMBradbury
New Member
- Joined
- Mar 8, 2023
- Messages
- 9
- Office Version
- 365
- Platform
- Windows
Hello,
I have a PO Signature approval form (SignatureApprovalForm), that has a text box that when clicked opens the frm_login. This is where the allowed users can put their username and password, that when they click cmd_login logs them in. I would like to then have the username of be inputted into the a field on the SignatureApprovalForm, field named txt_approval. When I test, I am getting a debug of the below. Also here is my code.
I am at a loss, and appreciate any insight.
I have a PO Signature approval form (SignatureApprovalForm), that has a text box that when clicked opens the frm_login. This is where the allowed users can put their username and password, that when they click cmd_login logs them in. I would like to then have the username of be inputted into the a field on the SignatureApprovalForm, field named txt_approval. When I test, I am getting a debug of the below. Also here is my code.
VBA Code:
Private Sub cmd_login_Click()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
Dim strUser As String
strUser = Me.txt_username
If Trim(Me.txt_username.Value & vbNullString) = vbNullString Then
MsgBox prompt:="Username should not be left blank.", buttons:=vbInformation, title:="Username Required"
Me.txt_username.SetFocus
Exit Sub
End If
If Trim(Me.txt_password.Value & vbNullString) = vbNullString Then
MsgBox prompt:="Password should not be left blank.", buttons:=vbInformation, title:="Password Required"
Me.txt_password.SetFocus
Exit Sub
End If
'query to check if login details are correct
strSQL = "SELECT FirstName FROM tbl_login WHERE Username = """ & Me.txt_username.Value & """ AND Password = """ & Me.txt_password.Value & """"
Set db = CurrentDb
Set rst = db.OpenRecordset(strSQL)
If rst.EOF Then
MsgBox prompt:="Incorrect username/password. Try again.", buttons:=vbCritical, title:="Login Error"
Me.txt_username.SetFocus
Else
MsgBox prompt:="Hello, " & rst.Fields(0).Value & ".", buttons:=vbOKOnly, title:="Login Successful"
Forms!SignatureApprovalForm.txt_approval = strUser
DoCmd.Close acForm, "frm_login", acSaveYes
End If
Set db = Nothing
Set rst = Nothing
End Sub
I am at a loss, and appreciate any insight.