-
The best way is to use an If, then statement and pop up a messsage box if a text box is blank , then when they OK the message box you can set focus back to that text box. Here's a little code sample:
'put this code in the click event or the event you use to check the text box contents
Dim iMsg As Integer
'
If txt1.Text = "" Then
iMsg = MsgBox("Please enter some text in text 1", vbOKOnly, "Missing entry")
txt1.SetFocus
Exit Sub
'
ElseIf txt2.Text = "" Then
iMsg = MsgBox("Please enter some text in text 2", vbOKOnly, "Missing entry")
txt2.SetFocus
Exit Sub
'etc
'etc
End If
hope this helps
cheers
:) john:)
-
If Text?.Text="" Then
msgbox "Fill in the field idiot!",vbCritical+vbokonly
exit sub
else
'code to fill in database
end if
OR
If Text?.Text="" Then
msgbox "Fill in the field idiot!",vbCritical+vbokonly
exit sub
end if
'code to fill in database
-
1 Attachment(s)
Add 1 box named txtArray and copy, then paste
Click yes when it asks do you want to create a control array
the put this code on your button:
Code:
Private Sub Command1_Click()
Dim ErrorsFound As Integer, i As Integer
ErrorsFound = 0
For i = 0 To txtArray.Count - 1
If txtArray(i).Text = "" Then
ErrorsFound = ErrorsFound + 1
End If
Next i
If ErrorsFound <> 0 Then
MsgBox ErrorsFound & " errors were found! Please rectify this situation", vbOKOnly
Exit Sub
End If
'Database Addition Code
End Sub
or download the following form :)
-
<?>
Code:
'Clear all textboxs on all forms or all textboxes on a single form
'You can do it this way without an array..but an array would be quicker
'if you were dealing with a lot of controls on a form
Option Explicit
'
Public Sub CheckTxt()
Dim ctlMyControl As Control
Dim intIncrement As Integer
For intIncrement = 0 To Forms.Count - 1
For Each ctlMyControl In Forms(intIncrement).Controls
If TypeOf ctlMyControl Is TextBox Then
If ctlMyControl.Text = "" Then
MsgBox "Sorry, you need to fill in all textboxes"
ctlMyControl.SetFocus
Exit Sub
End If
End If
'
Next ctlMyControl
Next intIncrement
End Sub
Private Sub Command1_Click()
Call CheckTxt
End Sub