Hello,
my goal is to allow a user to enable a text field based on a username and password input. My form is formatted in that, the text field (PoNbr) has a command button for a label. The idea is the command button is clicked, a login form pops open, a user puts their credentials in and the text box (PoNbr) is unlocked. But I'm not entirely sure how to incorporate that into my code. I'm struggling to write it in, where it looks for the form PurchaseReqHeader, selects the PoNbr text box and unlocks the field.
my goal is to allow a user to enable a text field based on a username and password input. My form is formatted in that, the text field (PoNbr) has a command button for a label. The idea is the command button is clicked, a login form pops open, a user puts their credentials in and the text box (PoNbr) is unlocked. But I'm not entirely sure how to incorporate that into my code. I'm struggling to write it in, where it looks for the form PurchaseReqHeader, selects the PoNbr text box and unlocks the field.
VBA Code:
Private Sub cmd_login()
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:="Login Successful, " & rst.Fields(0).Value & ".", buttons:=vbOKOnly, title:="Login Successful"
DoCmd.Close acForm, "frm_login_PurchasingPO", acSaveYes
' This is where I believe the code would need to go to select the field and enable editing.
End Sub