Validation Question

S

steve goodrich

I have a field on my form which can't contain a null value (validation rule
is - is nut null)

I have a command button "submit" which runs a simple macro which is, Go to
new record, sets the focus to "Date from" and displays a message box.



When the validation rule is broken I get the validation message, but then I
get an information box that states "you can't go to the specified record" I
click ok and then get a box showing me the macro that has failed and I have
to click HALT



Can I set it up so that when the validation rule is broken I get the
validation rule text only and not the 2 boxes informing me that the macro
has failed

Also if possible after clicking ok on the validation text box, the focus
would go to the relevant field that the rule has been applied to.



Thanks for any help



Steve
 
J

John Spencer

Are you using a macro to do this or are you using VBA code?

Whichever, you will have to check that there is a value in the
control(s) on the form and then display your own message and not attempt
to move to the next record.

In VBA that would be fairly easy. With a Macro, I think it could be
done, but

You would need to test each control, if it were null then you could move
to the control and stop the macro.

That would be something like:

IsNull(Forms![FormName]![txtDate]) : Move to Control (txtDate)

IsNull(Forms![FormName]![txtDate]) : Stop Macro

IsNull(Forms![FormName]![txtLastName]) : Move to Control (txtLastName)

IsNull(Forms![FormName]![txtLastName]) : Stop Macro

<< NO CONDITION >> : GoToRecord (New)
 
S

steve goodrich

Thanks for your help John, got it working
John Spencer said:
Are you using a macro to do this or are you using VBA code?

Whichever, you will have to check that there is a value in the control(s)
on the form and then display your own message and not attempt to move to
the next record.

In VBA that would be fairly easy. With a Macro, I think it could be done,
but

You would need to test each control, if it were null then you could move
to the control and stop the macro.

That would be something like:

IsNull(Forms![FormName]![txtDate]) : Move to Control (txtDate)

IsNull(Forms![FormName]![txtDate]) : Stop Macro

IsNull(Forms![FormName]![txtLastName]) : Move to Control (txtLastName)

IsNull(Forms![FormName]![txtLastName]) : Stop Macro

<< NO CONDITION >> : GoToRecord (New)



---
John Spencer
Access MVP 2001-2005, 2007


steve said:
I have a field on my form which can't contain a null value (validation
rule is - is nut null)

I have a command button "submit" which runs a simple macro which is, Go
to new record, sets the focus to "Date from" and displays a message box.



When the validation rule is broken I get the validation message, but then
I get an information box that states "you can't go to the specified
record" I click ok and then get a box showing me the macro that has
failed and I have to click HALT



Can I set it up so that when the validation rule is broken I get the
validation rule text only and not the 2 boxes informing me that the macro
has failed

Also if possible after clicking ok on the validation text box, the focus
would go to the relevant field that the rule has been applied to.



Thanks for any help



Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top