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

How to prompt a user if the user do not enter anything in the text box

Status
Not open for further replies.

tar28un

Technical User
Nov 29, 2005
58
GB
Hi there,

I am designing a form in access.
And I want to give a message to user to Enter value if the user leave some required text box blank. Due to some reason I could not set the required property to yes. So In the lost focus event of the box I want to write code that will check for the value in the text box and there is not anything in the form it will give a message and set the focus back to that text box

So I am writing here as:

if txthours.value is null then
msgbox"Please enter the no. of hours"
txthours.setfocus
endif
but I am getting the error msg saying object is required

Can anybody help?
 
Perhaps:
Code:
If IsNull(Me.txtHours) Then
    MsgBox "Please enter the no. of hours"
    Me.txtHours.SetFocus
End If
 
Hmm, posted too soon. You have not said what this box is formatted as (text, number, time etc), if it will allow spaces, you will need to check for that:
If Trim(Me.txtHours) & "" = "" Then ...
 
How are you validating the fields if they never click in a field that is required?
You may want to denote required fields on the form and then issue a cmdButton to process the data. The start of the process could be your error checking for required fields.
 
Many thanks to all of you
I am getting another problem now
the code is working now but the setfocus command does not set the focus to the required text box but after displaying the msgbox the focus jumps to next textbox
 
Hi there

My problem is solved now

Many thanks to all of you for prompt reply
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top