if user didn't enter info - error messages

deekras

Registered User.
Local time
Today, 20:49
Joined
Jun 14, 2000
Messages
169
i would like the program to alert the user to enter data if it was not entered as soon as the user passes that particular field.

right now i have the validation rule set to "Is not null" and a message. However, that message is displayed only it the user tries to go to the next record.

any suggestions?
 
Control event: On Exit (under properties, click on control and select the Events tab)

if isnull(me.fieldname) then
msgbox "Oh no you don't. Put something here!"
docmd.gotocontrol "Fieldname"
 
It does prompt me for the account now. But after i press enter to the OK on the message, it brings me to the field after account.

This is the coding i have now.

Private Sub Account_Exit(Cancel As Integer)
If IsNull(Me.Account) Then
MsgBox "You must enter an Account Number."
DoCmd.GoToControl "Account"
End If
End Sub
 
Really ... hmmmm.

Check your tab order (right-mouse click on anything and you'll see Tab Order ...)

I'll keep thinking...anybody else!?
 
Instead of:

Docmd.GotoControl Me!Account

try

Me(Account).SetFocus

as an alternative.
 
Since your code is trapping nulls when trying to move to the next record leave the code where it is in the form before update I suspect, since it is doing what you've intended why move it? Control exit lost focus etc. events will only work if the user tabs in and out of them, if they use the mouse to by-pass the control the form's before update is your only option
 
to the first replyer: i did try to change it to
Me![account].setfocus
didn't help. ( it is set on exit)

to the second replyer:
i am not using the mouse to bypass. i am simply pressing OK to the error message and when the error message box closes, i am at the next field.

any suggestions?
 
this is what i set up so far. it works, but it seems cumbersome. by every field on the form i put in this coding:

If IsNull(Me.company) Then
MsgBox ("You must enter a Company Name.")
DoCmd.GoToControl "Company"

Else
If IsNull(Me.Account) Then
MsgBox "You must enter an Account Number."
DoCmd.GoToControl "Account"
End If

End If

this way if the user tries to tab or use the mouse to get into any other field, it always prompts him to go back to either company, or if that is filled to account.

this works, but is there a better way?
 
I found this method to work perfectly fine...it forces the user to comply to your rule >>>and<<< stays put in the control, till the data is right!!
hope it helps
rgds
Uday
____________________________________
Private Sub CUSTOMER_Exit(Cancel As Integer)
If IsNull(Len(Trim(Me!CUSTOMER))) Then
MsgBox "You have left the customer's name blank.."
Cancel = True
Me!CUSTOMER.SetFocus
End If
End Sub
__________________________________________
 
Here is some code that I've used from another person on the forum.

THIS is expecially useful if there is more than ONE field on the form that needs to be REQUIRED.

----


'from KNX code of forum
'ERROR HANDLING

'Loops through all fields that have tag set as "validate"
'checks if they are null and stops user if they are
'highlights in yellow those fields null and then stops event


Dim currctl As Integer, numctls As Integer
Dim ctl As Control
numctls = Forms!frmMaterials.Count 'counts the number of controls on form

For currctl = 0 To numctls - 1
Set ctl = Me(currctl)

' do we want to check this control?

If ctl.Tag = "validate" Then
If IsNull(ctl) Then
MsgBox "You have not filled in information that is required by this database. Please fill in the fields highlighted in YELLOW.", 48, "Field empty"
ctl.BackColor = 65535
ctl.SetFocus
Exit Sub
End If
End If
Next currctl


'If all information required is filled out goto a new record

DoCmd.GoToRecord , , acNewRec
Me.Title.SetFocus
 

Users who are viewing this thread

Back
Top Bottom