how to check text box in MS Access

G

Guest

Suppose, I have 3 text boxes in the form. (text1 , text2 and text3)
after text1 lost focus I need to check that the text1.text is empty or not.
If it is null then show a messagebox and give text1 getfocus again.
 
G

Guest

Hi Sumeth,

You can use either the OnExit or BeforeUpdate events of each textbox to
check the value entered and prevent the user from progressing until the data
is valid eg;

Private Sub Text1_BeforeUpdate(Cancel As Integer)
If Isnull(Me.Text1) Then
msgbox("You must enter something into this textbox to continue")
Cancel = -1
End If
End Sub

and repeat as required for other textboxes,

hope this helps,

TonyT..
 
B

Brendan Reynolds

Private Sub Item_Exit(Cancel As Integer)

'checks for null only
If IsNull(Me.Item) Then
MsgBox "Hey! You forgot something!"
Cancel = True
End If

'also checks for empty strings
If Len(Me.Item & vbNullString) = 0 Then
MsgBox "Hey! You forgot something!"
Cancel = True
End If

End Sub
 
G

Guest

thanks all of you,
it can work well.

Brendan Reynolds said:
Private Sub Item_Exit(Cancel As Integer)

'checks for null only
If IsNull(Me.Item) Then
MsgBox "Hey! You forgot something!"
Cancel = True
End If

'also checks for empty strings
If Len(Me.Item & vbNullString) = 0 Then
MsgBox "Hey! You forgot something!"
Cancel = True
End If

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top