Going crazy try to create a validation macro!

R

RobH

I am simply trying to validate data in a form before updating. I can get the macro to run on the required condition but I can't get the desired result when "Cancel" is selected in the dialog box. Action Command - RunCode - MsgBox("Questionable entry, do you wish to save record?",1). The record is saved regardless if "OK" or "Cancel" is selected, I am going crazy!
 
S

Steve Schapel

Rob,

If you are going to use RunCode in a macro, you will need to set up
the full code for the process you want, which includes specifying what
you wanrt to happen for each of the message box responses. If you are
going to do that, I guess I can't see any point in a RunCode macro...
you might as well just put the code on the event and scrap the macro.
However, you can do this with a macro... In the macro Condition put...
MsgBox("Questionable entry, do you wish to save record?",4)=7
.... and then in the action, simply CancelEvent. This macro goes on
the form's BeforeUpdate event, right? I think this will achieve what
you want. The message box gives Yes and No buttons, if the answer is
Yes the record is saved, if it's No, the update is cancelled and the
user is returned to the form.

- Steve Schapel, Microsoft Access MVP
 
K

krash_control

I gave up on Macros when I discovered that with a little research VBA is
more powerful, flexible and easy to use.

here is the code you'd use in VBA (In your case I think you'd put it in
the after update event)


Code:
--------------------


If MsgBox("TEST", vbOKCancel) = vbOK Then
'Add record code here
Else
Exit Sub
'Code to run when cancel is pressed
End If
 
R

RobH

The condition needs to be a comparison of the data entered...for example "[new_data]<[other_data]", if this condition is true, the macro will run, otherwise no run. If the condition is true, RunCode....................... The problem is the record is saved regardless of what is selected in the dialog box (yes,no,OK,esc....). This macro is set to run before update of a form and is being used to validate data entered. If I can get it to work, I intend to validate several controls in the same macro. Is there a better way

Rob

----- Steve Schapel wrote: ----

Rob

If you are going to use RunCode in a macro, you will need to set u
the full code for the process you want, which includes specifying wha
you wanrt to happen for each of the message box responses. If you ar
going to do that, I guess I can't see any point in a RunCode macro..
you might as well just put the code on the event and scrap the macro
However, you can do this with a macro... In the macro Condition put..
MsgBox("Questionable entry, do you wish to save record?",4)=
.... and then in the action, simply CancelEvent. This macro goes o
the form's BeforeUpdate event, right? I think this will achieve wha
you want. The message box gives Yes and No buttons, if the answer i
Yes the record is saved, if it's No, the update is cancelled and th
user is returned to the form

- Steve Schapel, Microsoft Access MV


On Mon, 12 Jan 2004 21:36:11 -0800, "RobH
 
R

RobH

I finally figured it out, thanks Steve

----- RobH wrote: ----

The condition needs to be a comparison of the data entered...for example "[new_data]<[other_data]", if this condition is true, the macro will run, otherwise no run. If the condition is true, RunCode....................... The problem is the record is saved regardless of what is selected in the dialog box (yes,no,OK,esc....). This macro is set to run before update of a form and is being used to validate data entered. If I can get it to work, I intend to validate several controls in the same macro. Is there a better way

Rob

----- Steve Schapel wrote: ----

Rob

If you are going to use RunCode in a macro, you will need to set u
the full code for the process you want, which includes specifying wha
you wanrt to happen for each of the message box responses. If you ar
going to do that, I guess I can't see any point in a RunCode macro..
you might as well just put the code on the event and scrap the macro
However, you can do this with a macro... In the macro Condition put..
MsgBox("Questionable entry, do you wish to save record?",4)=
.... and then in the action, simply CancelEvent. This macro goes o
the form's BeforeUpdate event, right? I think this will achieve wha
you want. The message box gives Yes and No buttons, if the answer i
Yes the record is saved, if it's No, the update is cancelled and th
user is returned to the form

- Steve Schapel, Microsoft Access MV


On Mon, 12 Jan 2004 21:36:11 -0800, "RobH
 
R

RDH

I can not do the above myself if anyone can help???
I am trying to set up a macro that will cancel a record being saved should a field not be completed. I am using the beforeupdate on the form properties. It looks like this

[PracticeID] is null - Cancel Event
..... - MsgBox
..... - GotoControl

What am I doing wrong??????? I think we have wanted similar outcomes and you may have the answer

Thanks
Rachel

----- RobH wrote: -----

I am simply trying to validate data in a form before updating. I can get the macro to run on the required condition but I can't get the desired result when "Cancel" is selected in the dialog box. Action Command - RunCode - MsgBox("Questionable entry, do you wish to save record?",1). The record is saved regardless if "OK" or "Cancel" is selected, I am going crazy!
 

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