Hello..
I found this code in another thread and I can't seem to get it to work.
It won't let me add any new entry's into the database. I have a search function that allows me to check if there an employee number currently in the database. If not, I try to make the entry and it kicks up an error that the "employeenumber" is already in the database. Can't seem to figure out what is going on.
Here is the code I am using to search just in case it might have something to do with it.
Thanks for looking and if you need anything else please let me know.
I found this code in another thread and I can't seem to get it to work.
Code:
Private Sub form_beforeupdate(Cancel As Integer)
Dim icount As Long
icount = Nz(DLookup("EmployeeNumber", "tblMain", txtEmployeeNumber=" & Me.txtEmployeeNumber), 0)
If icount <> 0 Then
Beep
MsgBox "Worker ID all ready exists. You must choose an uniqe ID number!"
Cancel = True
Undo
End If
End Sub
It won't let me add any new entry's into the database. I have a search function that allows me to check if there an employee number currently in the database. If not, I try to make the entry and it kicks up an error that the "employeenumber" is already in the database. Can't seem to figure out what is going on.
Here is the code I am using to search just in case it might have something to do with it.
Code:
Private Sub cmdSearch_Click()
Dim strEmployeeNumber As String
Dim strSearch As String
'Check txtSearch for Null value or Nill Entry first.
If IsNull(Me![txtSearch]) Or (Me![txtSearch]) = "" Then
MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criterion!"
Me![txtSearch].SetFocus
Exit Sub
End If
'Performs the search using value entered into txtSearch
'and evaluates this against values in strStudentID
DoCmd.ShowAllRecords
DoCmd.GoToControl ("txtEmployeeNumber")
DoCmd.FindRecord Me!txtSearch
txtEmployeeNumber.SetFocus
strEmployeeNumber = txtEmployeeNumber.Text
txtSearch.SetFocus
strSearch = txtSearch.Text
'If matching record found sets focus in strStudentID and shows msgbox
'and clears search control
If strEmployeeNumber = strSearch Then
'MsgBox "Match Found For: " & strSearch, , "Congratulations!"
txtEmployeeNumber.SetFocus
txtSearch = ""
'If value not found sets focus back to txtSearch and shows msgbox
Else
MsgBox "Match Not Found For: " & strSearch & " - Please Try Again.", _
, "Invalid Search Criterion!"
txtSearch.SetFocus
End If
End Sub
Thanks for looking and if you need anything else please let me know.
Last edited: