Handling Empty text box

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have an unbound textbox that I use to search for and jump to specific
records. Everything works fine until the user clears the textbox.

Here is the code I use:

Dim rs As DAO.Recordset
Set rs = Me.Recordset.Clone
rs.FindFirst BuildCriteria("[PlantID]", dbText, PlantIDFilterBox)
If Not rs.NoMatch Then
Me.Bookmark = rs.Bookmark
Else
MsgBox "PlantID Not Found!", vbExclamation, "Warning"
End If
rs.Close
Set rs = Nothing

If the textbox is empty and the After Update event is fired, I get an
"Invalid Use of Null" runtime error (94). How do I check for an empty
textbox? What would be a good course of action?

Thanks

Dave
 
David M C wrote in message
I have an unbound textbox that I use to search for and jump to specific
records. Everything works fine until the user clears the textbox.

Here is the code I use:

Dim rs As DAO.Recordset
Set rs = Me.Recordset.Clone
rs.FindFirst BuildCriteria("[PlantID]", dbText, PlantIDFilterBox)
If Not rs.NoMatch Then
Me.Bookmark = rs.Bookmark
Else
MsgBox "PlantID Not Found!", vbExclamation, "Warning"
End If
rs.Close
Set rs = Nothing

If the textbox is empty and the After Update event is fired, I get an
"Invalid Use of Null" runtime error (94). How do I check for an empty
textbox? What would be a good course of action?

Thanks

Dave

I would suppose it is because the BuildCriteria function expects the
expression to be a string, and dislikes Null. Try enclosing your
routine with an If statement

If len(Me!PlantIDFilterBox.Value & vbNullString) > 0 Then
Dim rs As DAO.Recordset
' ... rest of the code
Else
' form control doesn't contain anything - a messagebox, or just
' don't do anything?
End If
 
Thanks, all working now.

RoyVidar said:
David M C wrote in message
I have an unbound textbox that I use to search for and jump to specific
records. Everything works fine until the user clears the textbox.

Here is the code I use:

Dim rs As DAO.Recordset
Set rs = Me.Recordset.Clone
rs.FindFirst BuildCriteria("[PlantID]", dbText, PlantIDFilterBox)
If Not rs.NoMatch Then
Me.Bookmark = rs.Bookmark
Else
MsgBox "PlantID Not Found!", vbExclamation, "Warning"
End If
rs.Close
Set rs = Nothing

If the textbox is empty and the After Update event is fired, I get an
"Invalid Use of Null" runtime error (94). How do I check for an empty
textbox? What would be a good course of action?

Thanks

Dave

I would suppose it is because the BuildCriteria function expects the
expression to be a string, and dislikes Null. Try enclosing your
routine with an If statement

If len(Me!PlantIDFilterBox.Value & vbNullString) > 0 Then
Dim rs As DAO.Recordset
' ... rest of the code
Else
' form control doesn't contain anything - a messagebox, or just
' don't do anything?
End If
 
How did you incorporate the code? I'm still getting the error message
(invalid use of null)...this is what I have.

Private Sub Text52_AfterUpdate()
If Len(Me!Sales_Order.Value & vbNullString) > 0 Then
Dim rs As DAO.Recordset
Set rs = Me.Recordset.Clone
rs.FindFirst BuildCriteria("[Sales_Order]", dbText, Text52)
If Not rs.NoMatch Then
Me.Bookmark = rs.Bookmark
Else
MsgBox "Sales Order Not Found", vbExclamation, "Warning"
End If
rs.Close
Set rs = Nothing
Else
MsgBox "Sales Order Not Found", vbExclamation, "Warning"
End If
End Sub

RoyVidar said:
David M C wrote in message
I have an unbound textbox that I use to search for and jump to specific
records. Everything works fine until the user clears the textbox.

Here is the code I use:

Dim rs As DAO.Recordset
Set rs = Me.Recordset.Clone
rs.FindFirst BuildCriteria("[PlantID]", dbText, PlantIDFilterBox)
If Not rs.NoMatch Then
Me.Bookmark = rs.Bookmark
Else
MsgBox "PlantID Not Found!", vbExclamation, "Warning"
End If
rs.Close
Set rs = Nothing

If the textbox is empty and the After Update event is fired, I get an
"Invalid Use of Null" runtime error (94). How do I check for an empty
textbox? What would be a good course of action?

Thanks

Dave

I would suppose it is because the BuildCriteria function expects the
expression to be a string, and dislikes Null. Try enclosing your
routine with an If statement

If len(Me!PlantIDFilterBox.Value & vbNullString) > 0 Then
Dim rs As DAO.Recordset
' ... rest of the code
Else
' form control doesn't contain anything - a messagebox, or just
' don't do anything?
End If
 
Back
Top