Validating data

  • Thread starter Thread starter Greg
  • Start date Start date
G

Greg

Guest
I have created a form with a number of fields, all of which require data entry. All but a few of the initial fields require the user to enter from a short validated drop down list. All fields can be tabbed into. Each field has a macro that advises what data can be entered in that field if the wrong data is entered. In the event that the user attempts to leave the field without entering data, I wish the macro to run and return the user to the empty data field.

If the answer is to use the expression builder or the code builder, please list it as such, as I am still new enought that I may not pick up on which one is to be used.

Thanks in advance for your help.
 
sorry i don't have a specific answer for you as Im still new to this to but maybe this can help you get started.
If it were one field this is what I would do
If field name = "" Or IsNull(fieldname) Or IsEmpty(fieldname) Then
fieldname.setfocus

or something along those lines so that when it reads the field is empty it sets the focus back to that field, you said you have a bunch of fields so you'll need to write a short function to do this.Im sure someone else will have a better solution but I hope this helps you along the way for now

Rpb
 
You can also write this code using the code builder for the Exit event for each field.
If IsNull(FieldName) Then
Cancel = True
End If
 
i tried to do this too, but i get a error message: Expected function or variable;

This is my coding:

If [debit amount] = 0 Then
MsgBox "You must enter the amount of the transaction.", 0, "Can not be saved. Missing Data"
Me.[debit amount].SetFocus = True

I tried to do DoCmd.GoToControl "debit amount"

it skips to the next record and goes to "debit amount"
 
i figured it out.

i use
DoCmd.GoToControl "[debit amount]"
cancel = true

it stays in the same record.
 
The correct syntax is debit_amount.SetFocus you don't need =True
HTH
 

Users who are viewing this thread

Back
Top Bottom