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

Required Field Message Box 1

Status
Not open for further replies.
Jun 2, 2004
66
US
I have a required field that if left blank, I would like a message box to appear that informs the user that the field is required. The code (that I have posted below) works, but not with my particular field which happens to be a combo box.
Is there a way to make this message box appear when the combo box field is left blank and user either tries to exit or proceed to the next field? Basically, I do not want the user to be able to move anywhere until the field has been populated.
I have tried the code in the field's Lost Focus and Exit Procedures and in the Form's Exit Procedure, but it still will not work.

Any ideas would be appreciated.

SEE CODE BELOW...

Private Sub Application_LostFocus()

If IsNull(Me.Application) Then
MsgBox "You must enter an application name"

End If
End Sub


 
Have you tried something like this ?
If Me.Application.ListIndex < 0 Then


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hi

how about

If Len(Trim(Nz(Me.Application,"")&"")) = 0 Then
MsgBox "You must enter an application name"

End If

also I would reconsider the use of the word Application as the control name, .Application is the name of an object in Access, and as such is a reserved word


Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Thanks, but neither of these worked.

PHV:
I got the following compile error.
Method or data member not found. (ListIndex was highlighted)

KenReay:
I got the following run-time error 438:
Object doesn't support this property or method.
 
Strangely enough, if there IS data in the combobox and I use the below code, the box appears. It's only when I get rid of the 'Not' and leave the field blank, that the box does not appear.
Not sure why this is


Private Sub Application_LostFocus()

If Not IsNull(Me.Application) Then
MsgBox "You must enter an application name"

End If
End Sub
 
Hi

"Object doesn't support this property or method"

Did you follow my advice to change control name?

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
And this ?
If Me.Controls("Application").ListIndex < 0 Then

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks KenReay. Renaming the control name did the trick.

Thanks also to PHV for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top