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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stop data entry on subform if control on form is Null

Status
Not open for further replies.

cariengon

Technical User
Mar 18, 2002
283
0
0
US
I am trying to not allow a user to enter any data into a subform on a form, if a control on the form is null. I've set the focus to be on the control when the form is loaded and then I'm assuming that if I do a Lost Focus event when the user somewhere on the subform, I'll get the message that I want.

What am I missing here? My code is the following:

Private Sub cbo_MonthYearSelect_LostFocus()
If Me.cbo_MonthYearSelect = Null Then
MsgBox "You must select a Month period.", vbOKOnly
Me.cbo_MonthYearSelect.SetFocus
End If
End Sub

Should I be trying to set the code on the gotfocus of the subform? I tried that and that doesn't seem to work either...

Any ideas?

Many, Many thanks in advance...
Carie

 
Okay - Step 2:

I just got this to work, by using IsNUll(cbo_...)

BUT, since I clicked on the subform it's not returning my focus to the control on the main form. I even tried using the
Forms![101_Issue_TimeEntry_frm]![cbo_MonthYearSelect].SetFocus
to ensure that the focus will go back to the main form.

Should I be using a version of this code on the load event of the subform - or the gotfocus event of the subform? I can't control what control the user will click on, so I don't want to tie it to a field. When I have tried it on the current or sfrm load, it doesn't seem to take the code...

UGGGGHHH!!
 
Private Sub Collections_subform_Enter()
If IsNull(Me.CustomerID) Then
Beep
MsgBox "There are no Customer details entered yet, please correct this"
txtSurname.SetFocus
End If
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top