Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Keep Focus? 1

Status
Not open for further replies.

Wrecker

Technical User
Aug 29, 2001
126
US
In the Lost focus property of a combo box I placed an if statment to check for text, and if no text is found, a msgbox "Must Select Name" appears. The problem is after the code runs, the focus goes to the next textbox in the tab order. I need the focus to remain in the combo box so the user can input the "Name" . Not sure where Im going wrong.
Here is the code im using:

If Me.Ins__.Text = "" Then
MsgBox "Must Select Name"
Me.Ins__.SetFocus
Exit Sub
End If

Thanks
Wrecker
 
No good.. There is no update if the user tries to leave the combo box empty and then exit.

Thanks
Wrecker
 
Wrecker:

If you make the control source for Ins_ a required field in the underlying table, the database will automatically issue an error and leave the cursor in the box.

Hope this helps

Vic
 
If you want another way of dealing with null fields. This will work on any form, because it's using a class module. I place the word Required in the tag property of the control that is required. Make a class module like this:

Public Function ValidateData(frm As Form) As String

Dim ctl As Control
For Each ctl In frm.Controls

If (TypeOf ctl Is TextBox Or TypeOf ctl Is ComboBox) And ctl.Tag = "Required" Then
If IsNull(ctl) Then
MsgBox "You need to enter data here."
ctl.SetFocus
End If
End If
Next ctl
End Function

And in the form's before update event do this:
Call ValidateData(Me)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top