For some reason I am not able to figure this out....I have been looking all over for the answer to no avail. I have a form (frmAddInmate) that has a textbox (txtCDCNum) on it. I have a table (tblInmates) that has several fields (ID, CDCNum, and other data) what I want to do is when someone enters a string in txtCDCNum and upon exiting the textbox the code checks to see if the string exists in the table in field CDCNum. If the string exists, then inform the user and return to the textbox.
I have tried several versions of FindFirst and checking if it is null and several versions of Dlookup. In researching this it seems like I am coding it correctly but it doesn't work. I have the identical thing on another form and it works perfectly.
Here is the code I am trying and the errors:
(This is the code that works on another form, the only differrence is that the other form the criteria is in a listbox)
Private Sub txtCDCNum_AfterUpdate()
Dim reply As String
' Find the record that matches the control.
Dim rs As Object
Set rs = Me.Recordset.Clone
txtCDCNum = StrConv(txtCDCNum, vbUpperCase)
rs.FindFirst "[ID] = " & Str(Nz(Me![txtCDCNum], 0))
If rs.EOF Then
Exit Sub
Else
reply = MsgBox("This CDC Number already exists", vbOKOnly, "Duplicate CDC numbers")
txtCDCNum.SetFocus
End If
End Sub
** the error I get is Type mismatch in the FindFirst code.
The Dlookup I tried is:
Private Sub txtCDCNum_AfterUpdate()
Dim reply As String, NumTest As String
txtCDCNum = StrConv(txtCDCNum, vbUpperCase)
If IsNull(NumTest = DLookup("[CDCNum]", "tblInmates", "[CDCNum]= '[me!txtCDCNum]'")) Then
Exit Sub
Else
reply = MsgBox("This CDC Number already exists", vbOKOnly, "Duplicate CDC numbers")
txtCDCNum.SetFocus
End If
End Sub
**This is always Null
Any suggestions?
I have tried several versions of FindFirst and checking if it is null and several versions of Dlookup. In researching this it seems like I am coding it correctly but it doesn't work. I have the identical thing on another form and it works perfectly.

Here is the code I am trying and the errors:
(This is the code that works on another form, the only differrence is that the other form the criteria is in a listbox)
Private Sub txtCDCNum_AfterUpdate()
Dim reply As String
' Find the record that matches the control.
Dim rs As Object
Set rs = Me.Recordset.Clone
txtCDCNum = StrConv(txtCDCNum, vbUpperCase)
rs.FindFirst "[ID] = " & Str(Nz(Me![txtCDCNum], 0))
If rs.EOF Then
Exit Sub
Else
reply = MsgBox("This CDC Number already exists", vbOKOnly, "Duplicate CDC numbers")
txtCDCNum.SetFocus
End If
End Sub
** the error I get is Type mismatch in the FindFirst code.
The Dlookup I tried is:
Private Sub txtCDCNum_AfterUpdate()
Dim reply As String, NumTest As String
txtCDCNum = StrConv(txtCDCNum, vbUpperCase)
If IsNull(NumTest = DLookup("[CDCNum]", "tblInmates", "[CDCNum]= '[me!txtCDCNum]'")) Then
Exit Sub
Else
reply = MsgBox("This CDC Number already exists", vbOKOnly, "Duplicate CDC numbers")
txtCDCNum.SetFocus
End If
End Sub
**This is always Null
Any suggestions?