Search Feature not working

T

Todd

I have a search feature on a main form where a user will enter a incident
number and it will bring up the record in a different form in order to edit
the data. When I try to use the feature, it will only provide the "Please
Enter a Valid Incident Number". The text box that I am using to enter the
value is called txt_incidentnum

Below is the code I am using. Can anyone see some stupid mistake I made?

Dim strwhere As String
Dim stDocName As String
If Me.txt_incidentnum > 0 Then
strwhere = "IncidentNo=" & Me.txt_incidentnum.Value
stDocName = "frm_DataEntry"
DoCmd.OpenForm stDocName, , , strwhere
Else
MsgBox "Please Enter a Valid Incident Number", vbExclamation, "Error"
Exit Sub
End If

Thanks
 
O

OfficeDev18 via AccessMonster.com

Todd,

Is IncidentNo a numeric field? Because usually, unbound form controls seem to
default to string, or even variant, data types. Try changing all incidents of
txt_incidentnum to CInt(txt_incidentnum) or CInt(txt_incidentnum.Value) and
see if the code works.

Hope this helps,

Sam
 
K

Klatuu

If IsNull(Me.txt_incindentnum) Then
MsgBox "Please Enter an Incident Number"
Exit Sub
End If

If IsNull(DLookup("[IncidentNum]", "MyTable", "[IncidentNum] = " & _
Me.txt_incidentnum)) Then
MsgBox "Please Enter a Valid Incident Number", vbExclamation, "Error"
Else
DoCmd.OpenForm "frm_DataEntry", , , "IncidentNo=" & Me.txt_incidentnum
End If
 
Top