OpenForm Macro and If/Then Logic

A

Amy

Hi-
I have very limited knowledge with Macros and logic expressions. I have created a db with several tables to track employee maintenance. On the main form, the user indicates what type of transaction (a list of values for a field) is to be performed. Based on the value of that field, I would like Access to take them to a specific form (after saving the data on the first form). I'm guessing this involves the OpenForm macro with some IF/Then logic as the Where Expression, but that's as much as I can figure out. I would appreciate help from anyone.

Much Thanks in advance -
Amy
 
K

Ken Snell

Use a Condition expression to have the macro make a decision based on the
value of a control on a form:

Condition: Forms!FormName!ControlName.Value = 1
Action: OpenForm
Form Name: Form1

Condition: Forms!FormName!ControlName.Value = 2
Action: OpenForm
Form Name: Form2

Condition: Forms!FormName!ControlName.Value = 3
Action: OpenForm
Form Name: Form3


etc.


--

Ken Snell
<MS ACCESS MVP>

Amy said:
Hi-
I have very limited knowledge with Macros and logic expressions. I have
created a db with several tables to track employee maintenance. On the main
form, the user indicates what type of transaction (a list of values for a
field) is to be performed. Based on the value of that field, I would like
Access to take them to a specific form (after saving the data on the first
form). I'm guessing this involves the OpenForm macro with some IF/Then
logic as the Where Expression, but that's as much as I can figure out. I
would appreciate help from anyone.
 
K

Ken Snell

Is AppointProcessing a subform on another form? It must be open on its own
for your condition statement to work.

--

Ken Snell
<MS ACCESS MVP>

Amy said:
Thanks Ken for the assistance. I'm having problems.

When I create a record on the AppointProcessing with a value of NHAP,
nothing happens. When I try to test the macro I get the error message "MS
Access can't find the form 'AppointProcessing' referred to in a macro
expression.".
Here's one of my condition statements:
[Forms]![AppointProcessing]![TransType]=[NHAP]
Action = OpenForm
Form Name = APNEWHIRE
View = Form
Window Mode = Normal

Thanks
Amy




Ken Snell said:
Use a Condition expression to have the macro make a decision based on the
value of a control on a form:

Condition: Forms!FormName!ControlName.Value = 1
Action: OpenForm
Form Name: Form1

Condition: Forms!FormName!ControlName.Value = 2
Action: OpenForm
Form Name: Form2

Condition: Forms!FormName!ControlName.Value = 3
Action: OpenForm
Form Name: Form3


etc.


--

Ken Snell
<MS ACCESS MVP>

have
created a db with several tables to track employee maintenance. On the main
form, the user indicates what type of transaction (a list of values for a
field) is to be performed. Based on the value of that field, I would like
Access to take them to a specific form (after saving the data on the first
form). I'm guessing this involves the OpenForm macro with some IF/Then
logic as the Where Expression, but that's as much as I can figure out. I
would appreciate help from anyone.
 
K

Ken Snell

Sorry - hit enter button too soon on just sent note.

If AppointProcessing is a subform, then the condition statement would need
to change:
[Forms]!MainFormName]![AppointProcessing]![TransType]="NHAP"

Also, don't surround NHAP (assuming that it's a text string) with [ ]
characters, but with " characters instead.
--

Ken Snell
<MS ACCESS MVP>


Amy said:
Thanks Ken for the assistance. I'm having problems.

When I create a record on the AppointProcessing with a value of NHAP,
nothing happens. When I try to test the macro I get the error message "MS
Access can't find the form 'AppointProcessing' referred to in a macro
expression.".
Here's one of my condition statements:
[Forms]![AppointProcessing]![TransType]=[NHAP]
Action = OpenForm
Form Name = APNEWHIRE
View = Form
Window Mode = Normal

Thanks
Amy




Ken Snell said:
Use a Condition expression to have the macro make a decision based on the
value of a control on a form:

Condition: Forms!FormName!ControlName.Value = 1
Action: OpenForm
Form Name: Form1

Condition: Forms!FormName!ControlName.Value = 2
Action: OpenForm
Form Name: Form2

Condition: Forms!FormName!ControlName.Value = 3
Action: OpenForm
Form Name: Form3


etc.


--

Ken Snell
<MS ACCESS MVP>

have
created a db with several tables to track employee maintenance. On the main
form, the user indicates what type of transaction (a list of values for a
field) is to be performed. Based on the value of that field, I would like
Access to take them to a specific form (after saving the data on the first
form). I'm guessing this involves the OpenForm macro with some IF/Then
logic as the Where Expression, but that's as much as I can figure out. I
would appreciate help from anyone.
 
K

Ken Snell

"I attached the macro to the AppointProcessing Form"

To which event of the form?

--

Ken Snell
<MS ACCESS MVP>

Amy said:
Ken, thank you for your help.

I'm having problems with getting the macro to work. I created a macro group
Here's one of the macros in the group:
Condition = [Forms]![AppointProcessing]![TransType]=[NHAP]
Action = OpenForm
FormName = APNEWHIRE
View = Form
Window mode = Normal

I attached the macro to the AppointProcessing Form. When I saved the
record, nothing happens. When I exit the form, I receive an error message
"The object doesn't contain the automation object 'NHAP'.".
I've tried to test the macro, but don't understand the error message I
receive when I run the macro: "MS Access can't find the form
AppointProcessing referred to in a macro expression. The form you referenced
may be closed or may not exist in this database."
 
S

Steve Schapel

.... or, if the macro is being triggered from an event on the
AppointProcessing (form or subform), I think it should work just to put
this...
[TransType]="NHAP"
 
A

Amy

Ken -
I attached the macrogroup to the After Update event for the AppointProcessing form because I want the new form to open after I save the record on the main form (AppointProcessing).

Changing the [] to "" worked fine. Unfortuntately, I haven't had time to thoroughly test the macro.

Thanks
Amy
 
¹

¹Ú¹®¼ö

Amy said:
Ken -
I attached the macrogroup to the After Update event for the
AppointProcessing form because I want the new form to open after I save the
record on the main form (AppointProcessing).
Changing the [] to "" worked fine. Unfortuntately, I haven't had time to thoroughly test the macro.

Thanks
Amy
 

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