Error checking

D

Dudley

Forms in my database have one set of command buttons which open other forms
(and close the current form) for the same record, and another set of command
buttons which copy data between fields. I would like to perform (the same)
error checking whenever any of these command buttons are clicked.

I have tried doing this as an event procedure in Form Properties 'On Close',
but this does not work the first time I click a button, although for some
reason it does work if I go back to the form and click a second time. I have
also tried putting the event procedure in 'On Cmd Before Execute', but this
did not work.

Can anyone help?

Thanks very much
Dudley
 
D

Dudley

Thanks very much for your help. Or could I adapt this follows?

Public Function fnErrorCheck() as Boolean

If Rule1 is broken then
fnErrorCheck=False
and
msgbox "Error message 1"

Endif

and then on the click event

If fnErrorCheck=False then
end function
Else
do that thing you do if the rules pass
Endif

Dudley
 
D

Dudley

Thanks very much for your help. Some further points:

1. I seem to remember that in eg

If Len(Trim(Nz(Me.ROAddress1, ""))) <> 0 And Len(Trim(Nz(Me.ROPostTown,
""))) = 0 Then

the Me. only works in a sub, not in a function. Is this correct and if so
how should it be shown in a function?

2. Can I say that two fields cannot be the same with

If Type1 = Type2 then
fnErrorCheck=False

3. Is it possible to specify that if Type1 = 1 then Data1 must be three
numbers and if Type1 = 2 then Data1 must be three letters and if so how do I
do this?

Many thanks if you can help on these points.
Dudley

tkelley via AccessMonster.com said:
That should work ... except your click event is a sub, so that would be an
'Exit Sub' where you have 'end function'
Thanks very much for your help. Or could I adapt this follows?

Public Function fnErrorCheck() as Boolean

If Rule1 is broken then
fnErrorCheck=False
and
msgbox "Error message 1"

Endif

and then on the click event

If fnErrorCheck=False then
end function
Else
do that thing you do if the rules pass
Endif

Dudley
In a module:
=================================
[quoted text clipped - 44 lines]
Thanks very much
Dudley
 
D

Dudley

Thanks very much for your help.
Dudley

tkelley via AccessMonster.com said:
1) If you need it to use on other forms, have it in an outside module. Then,
no you can't use 'Me.' However, if you only need it in that form, put it in
that form's code. Then you can use 'Me.'

2) Yes. You can use syntax like that. If you can do it in a sub, you can
do it in a function.

3) Look at the 'IsNumeric' function in help. You can use:

If IsNumeric(x) then ...

or

If Not IsNumeric(x) then ...
Thanks very much for your help. Some further points:

1. I seem to remember that in eg

If Len(Trim(Nz(Me.ROAddress1, ""))) <> 0 And Len(Trim(Nz(Me.ROPostTown,
""))) = 0 Then

the Me. only works in a sub, not in a function. Is this correct and if so
how should it be shown in a function?

2. Can I say that two fields cannot be the same with

If Type1 = Type2 then
fnErrorCheck=False

3. Is it possible to specify that if Type1 = 1 then Data1 must be three
numbers and if Type1 = 2 then Data1 must be three letters and if so how do I
do this?

Many thanks if you can help on these points.
Dudley
That should work ... except your click event is a sub, so that would be an
'Exit Sub' where you have 'end function'
[quoted text clipped - 25 lines]
Thanks very much
Dudley
 

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