exit sub on validation rule violation

G

Guest

I have validation rules tagged to bound controls on a form. i would like to
call a function that exits the subroutine if the validation rule is violated.
right now, the subroutine continues even though the validation rule was
violated. i.e. the next form opens when a validation rule on the previous
form is violated...i can't seem to figure out the appropriate syntax....does
anyone have any easy solutions?
thanks
 
T

Terry Kreft

Why not try showing us the code you have, that way we don't have to use our
psychic powers to work out the answer.
 
G

Guest

the code goes something like this:

private sub addrecord

'the user enters data on the form

call validation ' this is the function that i want to check to ensure all
validation rules are satisfied

DoCmd.GoToRecord , , acNewRec
DoCmd.OpenForm "nextform", , ,
docmd.Close "thisform", , ,
end sub

function validation
??? 'i want to check validation and if the rules are not satisfied than i
want to end the routine 'addrecord', so 'nextform' doesn't open and the
record isn't added...
end function

does this help??...the code isn't the exact syntax (it works)...but i'm sure
you get the gist of it...

thanks
 
T

Terry Kreft

What you do is have your validation function return a value to indicate
whether the values entered are valid, if they are run your other code if
they're not then skip them.


e.g.
private sub addrecord

If ValidData Then
DoCmd.GoToRecord , , acNewRec
DoCmd.OpenForm "nextform", , ,
docmd.Close "thisform", , ,
End if
end sub

Private Function ValidData() as boolean
' do your test and return true if the data is valid
' otherwise return false.
End Function
 
G

Guest

Hi Terry,

sorry about my delay in response...I was away for the last week...

I appreciate your help, but the problem is.... How do I check if the data
entry is valid within the function? What would be the syntax? Is there a
built-in function for this?

let's say i have a textbox called "txtbox"

if txtbox.value = valid(?) then
validdata = true
else
validdata = false
end if

I'm not sure how to question if the value is valid....

thanks again
 

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