Hello,
I am working on a database where i have created a dialog / input form to allow users to enter a key into a textbox to view particular data on a display form. I want the db to check the key entered and see if it matches the key already stored in a existing table if not then i want it to display an error msge. I am new to vba. Please can ne one look at the code and let me knw what i need to add or remove.
BELOW IS THE CODE FOR THE "OK" BUTTON AFTER THE USER WILL ENTER THE KEY(EMPNO)ON THE DIALOG/INPUT FORM. DB WILL USE THIS FORM TO MATCH KEY.
Private Sub Command2_Click()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strEmpNo As String
strEmpNo = txtInsertEmp
Set db = CurrentDb()
Set rst = db.OpenRecordset("tblCaretakers")
rst.MoveFirst
Do Until rst.EOF
With rst
If !EMPNUMB = strEmpNo Then
DoCmd.OpenForm "CaretakerDetails"
Else
.MoveNext
End If
End With
Loop
Set rst = Nothing
Set db = Nothing
End Sub
BELOW IS THE CODE FOR THE "FIND EMPLOYEE CODE" BUTTON THAT WILL DISPLAY THE ABOVE DIALOG/INPUT FORM THAT IS GOING TO DISPLAY THE DATA THAT MATCHES THE KEY WHICH IS ENTERED BY USER.
Private Sub CmdFindCode_Click()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strCode As String
Const vbinformation = 64
On Error GoTo CmdFindErr
DoCmd.ShowAllRecords
DoCmd.ApplyFilter "", "[tblCaretakers]![EMPNUMB]=[Enter Employee No]"
'DoCmd.OpenForm "DialogueEnterEmpNo"
CmdFind_Click_Exit:
Exit Sub
CmdFindErr:
Select Case Err
Case 2501 'Find Course Reference Action Cancelled
MsgBox _
"You Have Cancelled Finding a Employee by its No", _
vbinformation, "Action Cancelled"
Case Else
MsgBox "Error: " & Error & " (" & Err & ")"
End Select
Resume CmdFind_Click_Exit
End Sub
Can someone tell me what is wrong with this code and what i need to do make the db to check what is entered in the text box and match it with the key in a table. If a incorrect key is entered i want it to display a error msge.
I would be so grateful if ne one can help me on this one.
THANKYOU!! (",)
I am working on a database where i have created a dialog / input form to allow users to enter a key into a textbox to view particular data on a display form. I want the db to check the key entered and see if it matches the key already stored in a existing table if not then i want it to display an error msge. I am new to vba. Please can ne one look at the code and let me knw what i need to add or remove.
BELOW IS THE CODE FOR THE "OK" BUTTON AFTER THE USER WILL ENTER THE KEY(EMPNO)ON THE DIALOG/INPUT FORM. DB WILL USE THIS FORM TO MATCH KEY.
Private Sub Command2_Click()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strEmpNo As String
strEmpNo = txtInsertEmp
Set db = CurrentDb()
Set rst = db.OpenRecordset("tblCaretakers")
rst.MoveFirst
Do Until rst.EOF
With rst
If !EMPNUMB = strEmpNo Then
DoCmd.OpenForm "CaretakerDetails"
Else
.MoveNext
End If
End With
Loop
Set rst = Nothing
Set db = Nothing
End Sub
BELOW IS THE CODE FOR THE "FIND EMPLOYEE CODE" BUTTON THAT WILL DISPLAY THE ABOVE DIALOG/INPUT FORM THAT IS GOING TO DISPLAY THE DATA THAT MATCHES THE KEY WHICH IS ENTERED BY USER.
Private Sub CmdFindCode_Click()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strCode As String
Const vbinformation = 64
On Error GoTo CmdFindErr
DoCmd.ShowAllRecords
DoCmd.ApplyFilter "", "[tblCaretakers]![EMPNUMB]=[Enter Employee No]"
'DoCmd.OpenForm "DialogueEnterEmpNo"
CmdFind_Click_Exit:
Exit Sub
CmdFindErr:
Select Case Err
Case 2501 'Find Course Reference Action Cancelled
MsgBox _
"You Have Cancelled Finding a Employee by its No", _
vbinformation, "Action Cancelled"
Case Else
MsgBox "Error: " & Error & " (" & Err & ")"
End Select
Resume CmdFind_Click_Exit
End Sub
Can someone tell me what is wrong with this code and what i need to do make the db to check what is entered in the text box and match it with the key in a table. If a incorrect key is entered i want it to display a error msge.
I would be so grateful if ne one can help me on this one.
THANKYOU!! (",)