after update macro on two fields

P

pedro

I would like to create an after update macro on a form that validates two
fields. Both fields require a text value entry. I would then like a message
box to appear to indicate to the user that field1 requires input and then to
set the focus on the field. After the user enters data in field1 and then
attempts to add a record, another message box would appear if field2 is
empty, indicating data entry is required and setting the focus on field2. If
field1 has data entered then the macro would default to field to field2. The
condition on the macro would be something like if field1 is null then message
box.

thanks
 
S

Steve Schapel

Pedro,

It seems to me that you would be better running this macro on the Before
Update event of the form itself. In which case, you have pretty much
outlined the actions for the macro...

Condition: [Field1] Is Null
Action: MsgBox
Message: "Entry required in Field1"

Condition: ...
Action: CancelEvent

Condition: ...
Action: GoToControl
Control Name: [Field1]

Condition: ...
Action: StopMacro

Condition: [Field2] Is Null
Action: MsgBox
Message: "Entry required in Field2"

Condition: ...
Action: CancelEvent

Condition: ...
Action: GoToControl
Control Name: [Field2]
 
P

pedro

Hi Steve,

I still have a problem with this as I receive a Access error message when
the macro runs 'You can't go to the specified record'. The form I am using is
tabed and the fields are on different tabs.

When both field1 and field2 are null and the user attempts to add a record,
the message box will appear 'entry required for field1' after clicking the OK
button the error message will appear 'You can't go to the specified record'
and the focus is set to field1. After data is entered in field1 and the user
attempts to add a record, the error message will display and set the focus to
field1. This sequence repeats in a loop.

thanks for your help.

Steve Schapel said:
Pedro,

It seems to me that you would be better running this macro on the Before
Update event of the form itself. In which case, you have pretty much
outlined the actions for the macro...

Condition: [Field1] Is Null
Action: MsgBox
Message: "Entry required in Field1"

Condition: ...
Action: CancelEvent

Condition: ...
Action: GoToControl
Control Name: [Field1]

Condition: ...
Action: StopMacro

Condition: [Field2] Is Null
Action: MsgBox
Message: "Entry required in Field2"

Condition: ...
Action: CancelEvent

Condition: ...
Action: GoToControl
Control Name: [Field2]

--
Steve Schapel, Microsoft Access MVP
I would like to create an after update macro on a form that validates two
fields. Both fields require a text value entry. I would then like a message
box to appear to indicate to the user that field1 requires input and then to
set the focus on the field. After the user enters data in field1 and then
attempts to add a record, another message box would appear if field2 is
empty, indicating data entry is required and setting the focus on field2. If
field1 has data entered then the macro would default to field to field2. The
condition on the macro would be something like if field1 is null then message
box.

thanks
 
S

Steve Schapel

Pedro,

Can you please give a complete rundown of the macro you have at the
moment, in a similar format to the way I showed you before? Conditions,
Actions, relevant Arguments. Thanks.
 
P

pedro

Hi Steve

The macro is as follows;

CONDITION ACTION
[Field1] Is Null MsgBox 'Entry required in field1'
Cancel Event
Go to Control
Stop Macro
[Field2] Is Null MsgBox 'Entry required in field2'
Cancel Event
GoToControl

thanks
 
S

Steve Schapel

Pedro,

Ok, thanks. The reason I asked is because I couldn't understand the
error message referring to "go to the specified record", because I don't
know what the "specified record" is - and I'm afraid I still don't!

However, just to clarify, have you entered an ellipsis, i.e. three dots
.... in the Condition column for the other actions in the macro besides
the MsgBox? You need to do this to tell Access that the CancelEvent etc
are all still covered by the same Condition.
 
U

Update PDF Output File Name In Access 07

Hello Steve-

I actually have a question regarding a different issue. I have automated a
number of files that are generated from Acess2007 via an output Macro to a
network location, but the issue I have is that in the output file name of the
macro I would like to enter a date format which appends to the file name, and
from an automated standpoint be able to update the date part of the file name
daily.
 
S

Steve Schapel

You can do it like this:

="C:\YourFolder\YourFile" & Format(Date(),"yymmdd") & ".pdf"
 

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

Similar Threads

Conditional Macro 2
2 options based on result 4
updated field 3
Variable field in macro 2
access form 1
DSum update query with multiple fields 0
Update Query question 2
Shift several columns in table 4

Top