Run Macro with Iff Statement

S

Steve

I cananot use visual basic code so I rely on what I know.
I want to run a Macro in a IIf statement
eg
IIf([Forms]![Lanes]![Type]=wood,Run Macro "A",RunMacro "B")
Could someone please give me a hand
Thanks
 
K

KARL DEWEY

Use the macro condition.
For Macro A set condition --
[Forms]![Lanes]![Type]="wood"

For Macro B set condition --
[Forms]![Lanes]![Type]<>"wood"
 
S

Steve

Thanks Karl,Im still lost I looking for help in writing the IIf statement
correctly, hope you can help me.--
Thanks from Down Under


KARL DEWEY said:
Use the macro condition.
For Macro A set condition --
[Forms]![Lanes]![Type]="wood"

For Macro B set condition --
[Forms]![Lanes]![Type]<>"wood"

--
KARL DEWEY
Build a little - Test a little


Steve said:
I cananot use visual basic code so I rely on what I know.
I want to run a Macro in a IIf statement
eg
IIf([Forms]![Lanes]![Type]=wood,Run Macro "A",RunMacro "B")
Could someone please give me a hand
Thanks
 
G

Graham R Seach

Steve,

Create the two macros, MacroA and MacroB, but also create another macro,
MacroC. Set MacroC as follows:
Line 1: Condition: [Forms]![form1]![text1]="wood"
Line 1: Action: RunMacro
Line 1: Macro Name: Macro1

Line 2: Condition: Nz([Forms]![form1]![text1],"")<>"wood"
Line 2: Action: RunMacro
Line 2: Macro Name: Macro2

To view the Conditions column, open the new macro and select [Conditions]
from the [View] menu.

Then just run Macro3 whenever you want to do it. For example, in the OnClick
property of a button, enter:
Macro3.
You're already using visual basic code by using the IIf function. All you'd
have to do is to enter the following into a VBA code module, for example,
the Click event of a button
If Nz(Forms!form1!text1,"") = "wood" Then DoCmd.RunMacro "Macro1" Else
DoCmd.RunMacro "Macro2"
....and do away with Macro3 altogether.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Steve said:
I cananot use visual basic code so I rely on what I know.
I want to run a Macro in a IIf statement
eg
IIf([Forms]![Lanes]![Type]=wood,Run Macro "A",RunMacro "B")
Could someone please give me a hand
Thanks
 
K

KARL DEWEY

Where are you going to put this IIF statement?
--
KARL DEWEY
Build a little - Test a little


Steve said:
Thanks Karl,Im still lost I looking for help in writing the IIf statement
correctly, hope you can help me.--
Thanks from Down Under


KARL DEWEY said:
Use the macro condition.
For Macro A set condition --
[Forms]![Lanes]![Type]="wood"

For Macro B set condition --
[Forms]![Lanes]![Type]<>"wood"

--
KARL DEWEY
Build a little - Test a little


Steve said:
I cananot use visual basic code so I rely on what I know.
I want to run a Macro in a IIf statement
eg
IIf([Forms]![Lanes]![Type]=wood,Run Macro "A",RunMacro "B")
Could someone please give me a hand
Thanks
 
S

Steve

I am giving it a go will Thank tou both for you help will be back if I do not
succeed
Regards Steve
 
S

Steve

Guys Im back,Graham I gave the code a go and It worked (feel like a hero)
but with one small problem, it did both operations.
Here is what the sub looked like.
Private Sub Command2_Click()
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro "Wood" Else
DoCmd.RunMacro "Synthetic"


End Sub
Can you see what I've done wrong
Steve
--
Thanks from Down Under


Graham R Seach said:
Steve,

Create the two macros, MacroA and MacroB, but also create another macro,
MacroC. Set MacroC as follows:
Line 1: Condition: [Forms]![form1]![text1]="wood"
Line 1: Action: RunMacro
Line 1: Macro Name: Macro1

Line 2: Condition: Nz([Forms]![form1]![text1],"")<>"wood"
Line 2: Action: RunMacro
Line 2: Macro Name: Macro2

To view the Conditions column, open the new macro and select [Conditions]
from the [View] menu.

Then just run Macro3 whenever you want to do it. For example, in the OnClick
property of a button, enter:
Macro3.
You're already using visual basic code by using the IIf function. All you'd
have to do is to enter the following into a VBA code module, for example,
the Click event of a button
If Nz(Forms!form1!text1,"") = "wood" Then DoCmd.RunMacro "Macro1" Else
DoCmd.RunMacro "Macro2"
....and do away with Macro3 altogether.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Steve said:
I cananot use visual basic code so I rely on what I know.
I want to run a Macro in a IIf statement
eg
IIf([Forms]![Lanes]![Type]=wood,Run Macro "A",RunMacro "B")
Could someone please give me a hand
Thanks
 
G

Graham R Seach

Steve,

The following two lines MUST appear on the SAME line!
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro "Wood" Else
DoCmd.RunMacro "Synthetic"

There are two ways to write an If..Then statement:
If x = y Then
'blah
Else
'blech
End If

....or...

If x = y Then blah Else blech

Notice the second option does not require an 'End If' clause. This option is
the one I recommended.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Steve said:
Guys Im back,Graham I gave the code a go and It worked (feel like a hero)
but with one small problem, it did both operations.
Here is what the sub looked like.
Private Sub Command2_Click()
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro "Wood" Else
DoCmd.RunMacro "Synthetic"


End Sub
Can you see what I've done wrong
Steve
--
Thanks from Down Under


Graham R Seach said:
Steve,

Create the two macros, MacroA and MacroB, but also create another macro,
MacroC. Set MacroC as follows:
Line 1: Condition: [Forms]![form1]![text1]="wood"
Line 1: Action: RunMacro
Line 1: Macro Name: Macro1

Line 2: Condition: Nz([Forms]![form1]![text1],"")<>"wood"
Line 2: Action: RunMacro
Line 2: Macro Name: Macro2

To view the Conditions column, open the new macro and select [Conditions]
from the [View] menu.

Then just run Macro3 whenever you want to do it. For example, in the
OnClick
property of a button, enter:
Macro3.
I cananot use visual basic code
You're already using visual basic code by using the IIf function. All
you'd
have to do is to enter the following into a VBA code module, for example,
the Click event of a button
If Nz(Forms!form1!text1,"") = "wood" Then DoCmd.RunMacro "Macro1"
Else
DoCmd.RunMacro "Macro2"
....and do away with Macro3 altogether.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Steve said:
I cananot use visual basic code so I rely on what I know.
I want to run a Macro in a IIf statement
eg
IIf([Forms]![Lanes]![Type]=wood,Run Macro "A",RunMacro "B")
Could someone please give me a hand
Thanks
 
S

Steve

Thanks Graham, I did as you said and put it all on one line,BUT, I am now
recieving an error message
Run-time error'2501'
The run macro action was cancelled. I pushed debug and
(If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro "Wood" ElseCheers
Steve Lismore NSW

--
Thanks from Down Under


Graham R Seach said:
Steve,

The following two lines MUST appear on the SAME line!
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro "Wood" Else
DoCmd.RunMacro "Synthetic"

There are two ways to write an If..Then statement:
If x = y Then
'blah
Else
'blech
End If

....or...

If x = y Then blah Else blech

Notice the second option does not require an 'End If' clause. This option is
the one I recommended.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Steve said:
Guys Im back,Graham I gave the code a go and It worked (feel like a hero)
but with one small problem, it did both operations.
Here is what the sub looked like.
Private Sub Command2_Click()
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro "Wood" Else
DoCmd.RunMacro "Synthetic"


End Sub
Can you see what I've done wrong
Steve
--
Thanks from Down Under


Graham R Seach said:
Steve,

Create the two macros, MacroA and MacroB, but also create another macro,
MacroC. Set MacroC as follows:
Line 1: Condition: [Forms]![form1]![text1]="wood"
Line 1: Action: RunMacro
Line 1: Macro Name: Macro1

Line 2: Condition: Nz([Forms]![form1]![text1],"")<>"wood"
Line 2: Action: RunMacro
Line 2: Macro Name: Macro2

To view the Conditions column, open the new macro and select [Conditions]
from the [View] menu.

Then just run Macro3 whenever you want to do it. For example, in the
OnClick
property of a button, enter:
Macro3.

I cananot use visual basic code
You're already using visual basic code by using the IIf function. All
you'd
have to do is to enter the following into a VBA code module, for example,
the Click event of a button
If Nz(Forms!form1!text1,"") = "wood" Then DoCmd.RunMacro "Macro1"
Else
DoCmd.RunMacro "Macro2"
....and do away with Macro3 altogether.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


I cananot use visual basic code so I rely on what I know.
I want to run a Macro in a IIf statement
eg
IIf([Forms]![Lanes]![Type]=wood,Run Macro "A",RunMacro "B")
Could someone please give me a hand
Thanks
 
G

Graham R Seach

Steve,

Why do you have the If statement enclosed in brackets? Delete the outer
brackets:
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro "Wood" Else
DoCmd.RunMacro "Synthetic"

If that doesn't fix it (and this shouldn't really make any difference at
all), but try enclosing the macro names in brackets.
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro("Wood") Else
DoCmd.RunMacro("Synthetic")

Also just to be sure you don't run into any other problems, change the
expression to cater for the fact that users may enter uppercase, lowercase
or mixed case.
If LCase(Nz(Forms!Lanes!Type, "") = "wood") Then ...

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Steve said:
Thanks Graham, I did as you said and put it all on one line,BUT, I am now
recieving an error message
Run-time error'2501'
The run macro action was cancelled. I pushed debug and
(If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro "Wood" ElseCheers
Steve Lismore NSW

--
Thanks from Down Under


Graham R Seach said:
Steve,

The following two lines MUST appear on the SAME line!
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro "Wood" Else
DoCmd.RunMacro "Synthetic"

There are two ways to write an If..Then statement:
If x = y Then
'blah
Else
'blech
End If

....or...

If x = y Then blah Else blech

Notice the second option does not require an 'End If' clause. This option
is
the one I recommended.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Steve said:
Guys Im back,Graham I gave the code a go and It worked (feel like a
hero)
but with one small problem, it did both operations.
Here is what the sub looked like.
Private Sub Command2_Click()
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro "Wood" Else
DoCmd.RunMacro "Synthetic"


End Sub
Can you see what I've done wrong
Steve
--
Thanks from Down Under


:

Steve,

Create the two macros, MacroA and MacroB, but also create another
macro,
MacroC. Set MacroC as follows:
Line 1: Condition: [Forms]![form1]![text1]="wood"
Line 1: Action: RunMacro
Line 1: Macro Name: Macro1

Line 2: Condition: Nz([Forms]![form1]![text1],"")<>"wood"
Line 2: Action: RunMacro
Line 2: Macro Name: Macro2

To view the Conditions column, open the new macro and select
[Conditions]
from the [View] menu.

Then just run Macro3 whenever you want to do it. For example, in the
OnClick
property of a button, enter:
Macro3.

I cananot use visual basic code
You're already using visual basic code by using the IIf function. All
you'd
have to do is to enter the following into a VBA code module, for
example,
the Click event of a button
If Nz(Forms!form1!text1,"") = "wood" Then DoCmd.RunMacro "Macro1"
Else
DoCmd.RunMacro "Macro2"
....and do away with Macro3 altogether.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


I cananot use visual basic code so I rely on what I know.
I want to run a Macro in a IIf statement
eg
IIf([Forms]![Lanes]![Type]=wood,Run Macro "A",RunMacro "B")
Could someone please give me a hand
Thanks
 
S

Steve

I must be a bit' D' but still the same, this is how it reads now'
Private Sub Command2_Click()
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro ("Wood") Else
DoCmd.RunMacro ("Synthetic") (all on one line)
Same error message as before When when I debug what ever action it has done
will be highlighted in yellow, and it is only doing that action where as
before it was doing both.
Thanks from Down Under


Graham R Seach said:
Steve,

Why do you have the If statement enclosed in brackets? Delete the outer
brackets:
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro "Wood" Else
DoCmd.RunMacro "Synthetic"

If that doesn't fix it (and this shouldn't really make any difference at
all), but try enclosing the macro names in brackets.
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro("Wood") Else
DoCmd.RunMacro("Synthetic")

Also just to be sure you don't run into any other problems, change the
expression to cater for the fact that users may enter uppercase, lowercase
or mixed case.
If LCase(Nz(Forms!Lanes!Type, "") = "wood") Then ...

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Steve said:
Thanks Graham, I did as you said and put it all on one line,BUT, I am now
recieving an error message
Run-time error'2501'
The run macro action was cancelled. I pushed debug and
(If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro "Wood" Else
DoCmd.RunMacro "Synthetic") the "DoCmd.RunMacro "Wood" Else" is
highlighted in yellow.
Cheers
Steve Lismore NSW

--
Thanks from Down Under


Graham R Seach said:
Steve,

The following two lines MUST appear on the SAME line!
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro "Wood" Else
DoCmd.RunMacro "Synthetic"

There are two ways to write an If..Then statement:
If x = y Then
'blah
Else
'blech
End If

....or...

If x = y Then blah Else blech

Notice the second option does not require an 'End If' clause. This option
is
the one I recommended.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Guys Im back,Graham I gave the code a go and It worked (feel like a
hero)
but with one small problem, it did both operations.
Here is what the sub looked like.
Private Sub Command2_Click()
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro "Wood" Else
DoCmd.RunMacro "Synthetic"


End Sub
Can you see what I've done wrong
Steve
--
Thanks from Down Under


:

Steve,

Create the two macros, MacroA and MacroB, but also create another
macro,
MacroC. Set MacroC as follows:
Line 1: Condition: [Forms]![form1]![text1]="wood"
Line 1: Action: RunMacro
Line 1: Macro Name: Macro1

Line 2: Condition: Nz([Forms]![form1]![text1],"")<>"wood"
Line 2: Action: RunMacro
Line 2: Macro Name: Macro2

To view the Conditions column, open the new macro and select
[Conditions]
from the [View] menu.

Then just run Macro3 whenever you want to do it. For example, in the
OnClick
property of a button, enter:
Macro3.

I cananot use visual basic code
You're already using visual basic code by using the IIf function. All
you'd
have to do is to enter the following into a VBA code module, for
example,
the Click event of a button
If Nz(Forms!form1!text1,"") = "wood" Then DoCmd.RunMacro "Macro1"
Else
DoCmd.RunMacro "Macro2"
....and do away with Macro3 altogether.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


I cananot use visual basic code so I rely on what I know.
I want to run a Macro in a IIf statement
eg
IIf([Forms]![Lanes]![Type]=wood,Run Macro "A",RunMacro "B")
Could someone please give me a hand
Thanks
 
G

Graham R Seach

Steve,

What happens if you double-click each macro on its own? Do they complete
successfully?

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Steve said:
I must be a bit' D' but still the same, this is how it reads now'
Private Sub Command2_Click()
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro ("Wood") Else
DoCmd.RunMacro ("Synthetic") (all on one line)
Same error message as before When when I debug what ever action it has
done
will be highlighted in yellow, and it is only doing that action where as
before it was doing both.
Thanks from Down Under


Graham R Seach said:
Steve,

Why do you have the If statement enclosed in brackets? Delete the outer
brackets:
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro "Wood" Else
DoCmd.RunMacro "Synthetic"

If that doesn't fix it (and this shouldn't really make any difference at
all), but try enclosing the macro names in brackets.
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro("Wood") Else
DoCmd.RunMacro("Synthetic")

Also just to be sure you don't run into any other problems, change the
expression to cater for the fact that users may enter uppercase,
lowercase
or mixed case.
If LCase(Nz(Forms!Lanes!Type, "") = "wood") Then ...

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Steve said:
Thanks Graham, I did as you said and put it all on one line,BUT, I am
now
recieving an error message
Run-time error'2501'
The run macro action was cancelled. I pushed debug and
(If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro "Wood" Else
DoCmd.RunMacro "Synthetic") the "DoCmd.RunMacro "Wood" Else" is
highlighted in yellow.
Cheers
Steve Lismore NSW

--
Thanks from Down Under


:

Steve,

The following two lines MUST appear on the SAME line!
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro "Wood" Else
DoCmd.RunMacro "Synthetic"

There are two ways to write an If..Then statement:
If x = y Then
'blah
Else
'blech
End If

....or...

If x = y Then blah Else blech

Notice the second option does not require an 'End If' clause. This
option
is
the one I recommended.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Guys Im back,Graham I gave the code a go and It worked (feel like a
hero)
but with one small problem, it did both operations.
Here is what the sub looked like.
Private Sub Command2_Click()
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro "Wood" Else
DoCmd.RunMacro "Synthetic"


End Sub
Can you see what I've done wrong
Steve
--
Thanks from Down Under


:

Steve,

Create the two macros, MacroA and MacroB, but also create another
macro,
MacroC. Set MacroC as follows:
Line 1: Condition: [Forms]![form1]![text1]="wood"
Line 1: Action: RunMacro
Line 1: Macro Name: Macro1

Line 2: Condition: Nz([Forms]![form1]![text1],"")<>"wood"
Line 2: Action: RunMacro
Line 2: Macro Name: Macro2

To view the Conditions column, open the new macro and select
[Conditions]
from the [View] menu.

Then just run Macro3 whenever you want to do it. For example, in
the
OnClick
property of a button, enter:
Macro3.

I cananot use visual basic code
You're already using visual basic code by using the IIf function.
All
you'd
have to do is to enter the following into a VBA code module, for
example,
the Click event of a button
If Nz(Forms!form1!text1,"") = "wood" Then DoCmd.RunMacro
"Macro1"
Else
DoCmd.RunMacro "Macro2"
....and do away with Macro3 altogether.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


I cananot use visual basic code so I rely on what I know.
I want to run a Macro in a IIf statement
eg
IIf([Forms]![Lanes]![Type]=wood,Run Macro "A",RunMacro "B")
Could someone please give me a hand
Thanks
 
S

Steve

Graham , When double clicked both macros worked fine. Triedto put LCase in
but didn't know where to put the closing bracket . Whe I put it at the end it
did not allow me.
By the way thanks for helping me out.
Steve
Thanks from Down Under


Graham R Seach said:
Steve,

What happens if you double-click each macro on its own? Do they complete
successfully?

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Steve said:
I must be a bit' D' but still the same, this is how it reads now'
Private Sub Command2_Click()
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro ("Wood") Else
DoCmd.RunMacro ("Synthetic") (all on one line)
Same error message as before When when I debug what ever action it has
done
will be highlighted in yellow, and it is only doing that action where as
before it was doing both.
Thanks from Down Under


Graham R Seach said:
Steve,

Why do you have the If statement enclosed in brackets? Delete the outer
brackets:
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro "Wood" Else
DoCmd.RunMacro "Synthetic"

If that doesn't fix it (and this shouldn't really make any difference at
all), but try enclosing the macro names in brackets.
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro("Wood") Else
DoCmd.RunMacro("Synthetic")

Also just to be sure you don't run into any other problems, change the
expression to cater for the fact that users may enter uppercase,
lowercase
or mixed case.
If LCase(Nz(Forms!Lanes!Type, "") = "wood") Then ...

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Thanks Graham, I did as you said and put it all on one line,BUT, I am
now
recieving an error message
Run-time error'2501'
The run macro action was cancelled. I pushed debug and
(If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro "Wood" Else
DoCmd.RunMacro "Synthetic") the "DoCmd.RunMacro "Wood" Else" is
highlighted in yellow.
Cheers
Steve Lismore NSW

--
Thanks from Down Under


:

Steve,

The following two lines MUST appear on the SAME line!
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro "Wood" Else
DoCmd.RunMacro "Synthetic"

There are two ways to write an If..Then statement:
If x = y Then
'blah
Else
'blech
End If

....or...

If x = y Then blah Else blech

Notice the second option does not require an 'End If' clause. This
option
is
the one I recommended.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Guys Im back,Graham I gave the code a go and It worked (feel like a
hero)
but with one small problem, it did both operations.
Here is what the sub looked like.
Private Sub Command2_Click()
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro "Wood" Else
DoCmd.RunMacro "Synthetic"


End Sub
Can you see what I've done wrong
Steve
--
Thanks from Down Under


:

Steve,

Create the two macros, MacroA and MacroB, but also create another
macro,
MacroC. Set MacroC as follows:
Line 1: Condition: [Forms]![form1]![text1]="wood"
Line 1: Action: RunMacro
Line 1: Macro Name: Macro1

Line 2: Condition: Nz([Forms]![form1]![text1],"")<>"wood"
Line 2: Action: RunMacro
Line 2: Macro Name: Macro2

To view the Conditions column, open the new macro and select
[Conditions]
from the [View] menu.

Then just run Macro3 whenever you want to do it. For example, in
the
OnClick
property of a button, enter:
Macro3.

I cananot use visual basic code
You're already using visual basic code by using the IIf function.
All
you'd
have to do is to enter the following into a VBA code module, for
example,
the Click event of a button
If Nz(Forms!form1!text1,"") = "wood" Then DoCmd.RunMacro
"Macro1"
Else
DoCmd.RunMacro "Macro2"
....and do away with Macro3 altogether.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


I cananot use visual basic code so I rely on what I know.
I want to run a Macro in a IIf statement
eg
IIf([Forms]![Lanes]![Type]=wood,Run Macro "A",RunMacro "B")
Could someone please give me a hand
Thanks
 
G

Graham R Seach

Steve,

OK, let's split this up to make it easier to debug. And let's also remove
any reserved word problem by enclosing the word "Type" in square brackets.

If Nz(Forms!Lanes![Type], "") = "wood" Then
DoCmd.RunMacro "Wood"
Else
DoCmd.RunMacro "Synthetic"
End If

Of course, the spelling of the two macros are correct, aren't they? "Wood"
and "Synthetic"?

Before running any code, select Compile from the Debug menu, and fix any
problems that arise from that. Then we can move on.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Steve said:
Graham , When double clicked both macros worked fine. Triedto put LCase in
but didn't know where to put the closing bracket . Whe I put it at the end
it
did not allow me.
By the way thanks for helping me out.
Steve
Thanks from Down Under


Graham R Seach said:
Steve,

What happens if you double-click each macro on its own? Do they complete
successfully?

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Steve said:
I must be a bit' D' but still the same, this is how it reads now'
Private Sub Command2_Click()
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro ("Wood") Else
DoCmd.RunMacro ("Synthetic") (all on one line)
Same error message as before When when I debug what ever action it has
done
will be highlighted in yellow, and it is only doing that action where
as
before it was doing both.
Thanks from Down Under


:

Steve,

Why do you have the If statement enclosed in brackets? Delete the
outer
brackets:
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro "Wood" Else
DoCmd.RunMacro "Synthetic"

If that doesn't fix it (and this shouldn't really make any difference
at
all), but try enclosing the macro names in brackets.
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro("Wood") Else
DoCmd.RunMacro("Synthetic")

Also just to be sure you don't run into any other problems, change the
expression to cater for the fact that users may enter uppercase,
lowercase
or mixed case.
If LCase(Nz(Forms!Lanes!Type, "") = "wood") Then ...

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Thanks Graham, I did as you said and put it all on one line,BUT, I
am
now
recieving an error message
Run-time error'2501'
The run macro action was cancelled. I pushed debug and
(If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro "Wood"
Else
DoCmd.RunMacro "Synthetic") the "DoCmd.RunMacro "Wood" Else" is
highlighted in yellow.
Cheers
Steve Lismore NSW

--
Thanks from Down Under


:

Steve,

The following two lines MUST appear on the SAME line!
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro "Wood"
Else
DoCmd.RunMacro "Synthetic"

There are two ways to write an If..Then statement:
If x = y Then
'blah
Else
'blech
End If

....or...

If x = y Then blah Else blech

Notice the second option does not require an 'End If' clause. This
option
is
the one I recommended.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Guys Im back,Graham I gave the code a go and It worked (feel
like a
hero)
but with one small problem, it did both operations.
Here is what the sub looked like.
Private Sub Command2_Click()
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro "Wood"
Else
DoCmd.RunMacro "Synthetic"


End Sub
Can you see what I've done wrong
Steve
--
Thanks from Down Under


:

Steve,

Create the two macros, MacroA and MacroB, but also create
another
macro,
MacroC. Set MacroC as follows:
Line 1: Condition: [Forms]![form1]![text1]="wood"
Line 1: Action: RunMacro
Line 1: Macro Name: Macro1

Line 2: Condition: Nz([Forms]![form1]![text1],"")<>"wood"
Line 2: Action: RunMacro
Line 2: Macro Name: Macro2

To view the Conditions column, open the new macro and select
[Conditions]
from the [View] menu.

Then just run Macro3 whenever you want to do it. For example, in
the
OnClick
property of a button, enter:
Macro3.

I cananot use visual basic code
You're already using visual basic code by using the IIf
function.
All
you'd
have to do is to enter the following into a VBA code module, for
example,
the Click event of a button
If Nz(Forms!form1!text1,"") = "wood" Then DoCmd.RunMacro
"Macro1"
Else
DoCmd.RunMacro "Macro2"
....and do away with Macro3 altogether.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


I cananot use visual basic code so I rely on what I know.
I want to run a Macro in a IIf statement
eg
IIf([Forms]![Lanes]![Type]=wood,Run Macro "A",RunMacro "B")
Could someone please give me a hand
Thanks
 
S

Steve

Evening Graham (I hope you get this in the morning)
This is a direct paste from visual basic.

Private Sub Password_AfterUpdate()
If Nz(Forms!Lanes![Type], "") = "wood" Then
DoCmd.RunMacro "Wood"
Else
DoCmd.RunMacro "Synthetic"
End If

I selected Compile out of the Debug menu and no messages were received.
Operated the control source and the correct macro worked but I also received
the following error message.
Run-time error 2501:
The RunMacro action was canceled.
Pressed Debug on error message and the macro that had just run was
highlighted in yellow.
I then then removed the [ ] brackets and tested again, with the same results.
Real frustrating I bet !! especially for you.
Thanks
Steve


--
Thanks from Down Under


Graham R Seach said:
Steve,

OK, let's split this up to make it easier to debug. And let's also remove
any reserved word problem by enclosing the word "Type" in square brackets.

If Nz(Forms!Lanes![Type], "") = "wood" Then
DoCmd.RunMacro "Wood"
Else
DoCmd.RunMacro "Synthetic"
End If

Of course, the spelling of the two macros are correct, aren't they? "Wood"
and "Synthetic"?

Before running any code, select Compile from the Debug menu, and fix any
problems that arise from that. Then we can move on.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Steve said:
Graham , When double clicked both macros worked fine. Triedto put LCase in
but didn't know where to put the closing bracket . Whe I put it at the end
it
did not allow me.
By the way thanks for helping me out.
Steve
Thanks from Down Under


Graham R Seach said:
Steve,

What happens if you double-click each macro on its own? Do they complete
successfully?

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


I must be a bit' D' but still the same, this is how it reads now'
Private Sub Command2_Click()
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro ("Wood") Else
DoCmd.RunMacro ("Synthetic") (all on one line)
Same error message as before When when I debug what ever action it has
done
will be highlighted in yellow, and it is only doing that action where
as
before it was doing both.
Thanks from Down Under


:

Steve,

Why do you have the If statement enclosed in brackets? Delete the
outer
brackets:
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro "Wood" Else
DoCmd.RunMacro "Synthetic"

If that doesn't fix it (and this shouldn't really make any difference
at
all), but try enclosing the macro names in brackets.
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro("Wood") Else
DoCmd.RunMacro("Synthetic")

Also just to be sure you don't run into any other problems, change the
expression to cater for the fact that users may enter uppercase,
lowercase
or mixed case.
If LCase(Nz(Forms!Lanes!Type, "") = "wood") Then ...

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Thanks Graham, I did as you said and put it all on one line,BUT, I
am
now
recieving an error message
Run-time error'2501'
The run macro action was cancelled. I pushed debug and
(If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro "Wood"
Else
DoCmd.RunMacro "Synthetic") the "DoCmd.RunMacro "Wood" Else" is
highlighted in yellow.
Cheers
Steve Lismore NSW

--
Thanks from Down Under


:

Steve,

The following two lines MUST appear on the SAME line!
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro "Wood"
Else
DoCmd.RunMacro "Synthetic"

There are two ways to write an If..Then statement:
If x = y Then
'blah
Else
'blech
End If

....or...

If x = y Then blah Else blech

Notice the second option does not require an 'End If' clause. This
option
is
the one I recommended.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Guys Im back,Graham I gave the code a go and It worked (feel
like a
hero)
but with one small problem, it did both operations.
Here is what the sub looked like.
Private Sub Command2_Click()
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro "Wood"
Else
DoCmd.RunMacro "Synthetic"


End Sub
Can you see what I've done wrong
Steve
--
Thanks from Down Under


:

Steve,

Create the two macros, MacroA and MacroB, but also create
another
macro,
MacroC. Set MacroC as follows:
Line 1: Condition: [Forms]![form1]![text1]="wood"
Line 1: Action: RunMacro
Line 1: Macro Name: Macro1

Line 2: Condition: Nz([Forms]![form1]![text1],"")<>"wood"
Line 2: Action: RunMacro
Line 2: Macro Name: Macro2

To view the Conditions column, open the new macro and select
[Conditions]
from the [View] menu.

Then just run Macro3 whenever you want to do it. For example, in
the
OnClick
property of a button, enter:
Macro3.

I cananot use visual basic code
You're already using visual basic code by using the IIf
function.
All
you'd
have to do is to enter the following into a VBA code module, for
example,
the Click event of a button
If Nz(Forms!form1!text1,"") = "wood" Then DoCmd.RunMacro
"Macro1"
Else
DoCmd.RunMacro "Macro2"
....and do away with Macro3 altogether.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


I cananot use visual basic code so I rely on what I know.
I want to run a Macro in a IIf statement
eg
IIf([Forms]![Lanes]![Type]=wood,Run Macro "A",RunMacro "B")
Could someone please give me a hand
Thanks
 
G

Graham R Seach

Steve,

OK, what do the individual macros do. I think something's happening in one
of the macros, so let's start looking there. Write out what they do,
line-by-line.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Steve said:
Evening Graham (I hope you get this in the morning)
This is a direct paste from visual basic.

Private Sub Password_AfterUpdate()
If Nz(Forms!Lanes![Type], "") = "wood" Then
DoCmd.RunMacro "Wood"
Else
DoCmd.RunMacro "Synthetic"
End If

I selected Compile out of the Debug menu and no messages were received.
Operated the control source and the correct macro worked but I also
received
the following error message.
Run-time error 2501:
The RunMacro action was canceled.
Pressed Debug on error message and the macro that had just run was
highlighted in yellow.
I then then removed the [ ] brackets and tested again, with the same
results.
Real frustrating I bet !! especially for you.
Thanks
Steve


--
Thanks from Down Under


Graham R Seach said:
Steve,

OK, let's split this up to make it easier to debug. And let's also remove
any reserved word problem by enclosing the word "Type" in square
brackets.

If Nz(Forms!Lanes![Type], "") = "wood" Then
DoCmd.RunMacro "Wood"
Else
DoCmd.RunMacro "Synthetic"
End If

Of course, the spelling of the two macros are correct, aren't they?
"Wood"
and "Synthetic"?

Before running any code, select Compile from the Debug menu, and fix any
problems that arise from that. Then we can move on.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Steve said:
Graham , When double clicked both macros worked fine. Triedto put LCase
in
but didn't know where to put the closing bracket . Whe I put it at the
end
it
did not allow me.
By the way thanks for helping me out.
Steve
Thanks from Down Under


:

Steve,

What happens if you double-click each macro on its own? Do they
complete
successfully?

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


I must be a bit' D' but still the same, this is how it reads now'
Private Sub Command2_Click()
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro ("Wood")
Else
DoCmd.RunMacro ("Synthetic") (all on one line)
Same error message as before When when I debug what ever action it
has
done
will be highlighted in yellow, and it is only doing that action
where
as
before it was doing both.
Thanks from Down Under


:

Steve,

Why do you have the If statement enclosed in brackets? Delete the
outer
brackets:
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro "Wood"
Else
DoCmd.RunMacro "Synthetic"

If that doesn't fix it (and this shouldn't really make any
difference
at
all), but try enclosing the macro names in brackets.
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro("Wood")
Else
DoCmd.RunMacro("Synthetic")

Also just to be sure you don't run into any other problems, change
the
expression to cater for the fact that users may enter uppercase,
lowercase
or mixed case.
If LCase(Nz(Forms!Lanes!Type, "") = "wood") Then ...

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Thanks Graham, I did as you said and put it all on one line,BUT,
I
am
now
recieving an error message
Run-time error'2501'
The run macro action was cancelled. I pushed debug and
(If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro "Wood"
Else
DoCmd.RunMacro "Synthetic") the "DoCmd.RunMacro "Wood" Else"
is
highlighted in yellow.
Cheers
Steve Lismore NSW

--
Thanks from Down Under


:

Steve,

The following two lines MUST appear on the SAME line!
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro "Wood"
Else
DoCmd.RunMacro "Synthetic"

There are two ways to write an If..Then statement:
If x = y Then
'blah
Else
'blech
End If

....or...

If x = y Then blah Else blech

Notice the second option does not require an 'End If' clause.
This
option
is
the one I recommended.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Guys Im back,Graham I gave the code a go and It worked (feel
like a
hero)
but with one small problem, it did both operations.
Here is what the sub looked like.
Private Sub Command2_Click()
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro
"Wood"
Else
DoCmd.RunMacro "Synthetic"


End Sub
Can you see what I've done wrong
Steve
--
Thanks from Down Under


:

Steve,

Create the two macros, MacroA and MacroB, but also create
another
macro,
MacroC. Set MacroC as follows:
Line 1: Condition: [Forms]![form1]![text1]="wood"
Line 1: Action: RunMacro
Line 1: Macro Name: Macro1

Line 2: Condition: Nz([Forms]![form1]![text1],"")<>"wood"
Line 2: Action: RunMacro
Line 2: Macro Name: Macro2

To view the Conditions column, open the new macro and select
[Conditions]
from the [View] menu.

Then just run Macro3 whenever you want to do it. For example,
in
the
OnClick
property of a button, enter:
Macro3.

I cananot use visual basic code
You're already using visual basic code by using the IIf
function.
All
you'd
have to do is to enter the following into a VBA code module,
for
example,
the Click event of a button
If Nz(Forms!form1!text1,"") = "wood" Then DoCmd.RunMacro
"Macro1"
Else
DoCmd.RunMacro "Macro2"
....and do away with Macro3 altogether.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


I cananot use visual basic code so I rely on what I know.
I want to run a Macro in a IIf statement
eg
IIf([Forms]![Lanes]![Type]=wood,Run Macro "A",RunMacro "B")
Could someone please give me a hand
Thanks
 
S

Steve

Morning Graham,
Macro (Wood)
1st Line (Action) Set Value, (Argument) [Forms]![Quoting
Master]![Hidden].Visible,Yes
2nd Line (Action) Stop Macro

Macro (Synthetic)
1st Line (Action) Open Form, (Argument) Synthetic,Form,,,,Normal
2nd Line (Action) Stop Macro

Regads
Steve
--
Thanks from Down Under


Graham R Seach said:
Steve,

OK, what do the individual macros do. I think something's happening in one
of the macros, so let's start looking there. Write out what they do,
line-by-line.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Steve said:
Evening Graham (I hope you get this in the morning)
This is a direct paste from visual basic.

Private Sub Password_AfterUpdate()
If Nz(Forms!Lanes![Type], "") = "wood" Then
DoCmd.RunMacro "Wood"
Else
DoCmd.RunMacro "Synthetic"
End If

I selected Compile out of the Debug menu and no messages were received.
Operated the control source and the correct macro worked but I also
received
the following error message.
Run-time error 2501:
The RunMacro action was canceled.
Pressed Debug on error message and the macro that had just run was
highlighted in yellow.
I then then removed the [ ] brackets and tested again, with the same
results.
Real frustrating I bet !! especially for you.
Thanks
Steve


--
Thanks from Down Under


Graham R Seach said:
Steve,

OK, let's split this up to make it easier to debug. And let's also remove
any reserved word problem by enclosing the word "Type" in square
brackets.

If Nz(Forms!Lanes![Type], "") = "wood" Then
DoCmd.RunMacro "Wood"
Else
DoCmd.RunMacro "Synthetic"
End If

Of course, the spelling of the two macros are correct, aren't they?
"Wood"
and "Synthetic"?

Before running any code, select Compile from the Debug menu, and fix any
problems that arise from that. Then we can move on.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Graham , When double clicked both macros worked fine. Triedto put LCase
in
but didn't know where to put the closing bracket . Whe I put it at the
end
it
did not allow me.
By the way thanks for helping me out.
Steve
Thanks from Down Under


:

Steve,

What happens if you double-click each macro on its own? Do they
complete
successfully?

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


I must be a bit' D' but still the same, this is how it reads now'
Private Sub Command2_Click()
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro ("Wood")
Else
DoCmd.RunMacro ("Synthetic") (all on one line)
Same error message as before When when I debug what ever action it
has
done
will be highlighted in yellow, and it is only doing that action
where
as
before it was doing both.
Thanks from Down Under


:

Steve,

Why do you have the If statement enclosed in brackets? Delete the
outer
brackets:
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro "Wood"
Else
DoCmd.RunMacro "Synthetic"

If that doesn't fix it (and this shouldn't really make any
difference
at
all), but try enclosing the macro names in brackets.
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro("Wood")
Else
DoCmd.RunMacro("Synthetic")

Also just to be sure you don't run into any other problems, change
the
expression to cater for the fact that users may enter uppercase,
lowercase
or mixed case.
If LCase(Nz(Forms!Lanes!Type, "") = "wood") Then ...

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Thanks Graham, I did as you said and put it all on one line,BUT,
I
am
now
recieving an error message
Run-time error'2501'
The run macro action was cancelled. I pushed debug and
(If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro "Wood"
Else
DoCmd.RunMacro "Synthetic") the "DoCmd.RunMacro "Wood" Else"
is
highlighted in yellow.
Cheers
Steve Lismore NSW

--
Thanks from Down Under


:

Steve,

The following two lines MUST appear on the SAME line!
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro "Wood"
Else
DoCmd.RunMacro "Synthetic"

There are two ways to write an If..Then statement:
If x = y Then
'blah
Else
'blech
End If

....or...

If x = y Then blah Else blech

Notice the second option does not require an 'End If' clause.
This
option
is
the one I recommended.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Guys Im back,Graham I gave the code a go and It worked (feel
like a
hero)
but with one small problem, it did both operations.
Here is what the sub looked like.
Private Sub Command2_Click()
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro
"Wood"
Else
DoCmd.RunMacro "Synthetic"


End Sub
Can you see what I've done wrong
Steve
--
Thanks from Down Under


:

Steve,

Create the two macros, MacroA and MacroB, but also create
another
macro,
MacroC. Set MacroC as follows:
Line 1: Condition: [Forms]![form1]![text1]="wood"
Line 1: Action: RunMacro
Line 1: Macro Name: Macro1

Line 2: Condition: Nz([Forms]![form1]![text1],"")<>"wood"
Line 2: Action: RunMacro
Line 2: Macro Name: Macro2

To view the Conditions column, open the new macro and select
[Conditions]
from the [View] menu.

Then just run Macro3 whenever you want to do it. For example,
in
the
OnClick
property of a button, enter:
Macro3.

I cananot use visual basic code
You're already using visual basic code by using the IIf
function.
All
you'd
have to do is to enter the following into a VBA code module,
for
example,
the Click event of a button
If Nz(Forms!form1!text1,"") = "wood" Then DoCmd.RunMacro
"Macro1"
Else
DoCmd.RunMacro "Macro2"
....and do away with Macro3 altogether.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


I cananot use visual basic code so I rely on what I know.
I want to run a Macro in a IIf statement
eg
IIf([Forms]![Lanes]![Type]=wood,Run Macro "A",RunMacro "B")
Could someone please give me a hand
Thanks
 
G

Graham R Seach

Steve,

Get rid of the Stop Macro actions.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Steve said:
Morning Graham,
Macro (Wood)
1st Line (Action) Set Value, (Argument) [Forms]![Quoting
Master]![Hidden].Visible,Yes
2nd Line (Action) Stop Macro

Macro (Synthetic)
1st Line (Action) Open Form, (Argument) Synthetic,Form,,,,Normal
2nd Line (Action) Stop Macro

Regads
Steve
--
Thanks from Down Under


Graham R Seach said:
Steve,

OK, what do the individual macros do. I think something's happening in
one
of the macros, so let's start looking there. Write out what they do,
line-by-line.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Steve said:
Evening Graham (I hope you get this in the morning)
This is a direct paste from visual basic.

Private Sub Password_AfterUpdate()
If Nz(Forms!Lanes![Type], "") = "wood" Then
DoCmd.RunMacro "Wood"
Else
DoCmd.RunMacro "Synthetic"
End If

I selected Compile out of the Debug menu and no messages were received.
Operated the control source and the correct macro worked but I also
received
the following error message.
Run-time error 2501:
The RunMacro action was canceled.
Pressed Debug on error message and the macro that had just run was
highlighted in yellow.
I then then removed the [ ] brackets and tested again, with the same
results.
Real frustrating I bet !! especially for you.
Thanks
Steve


--
Thanks from Down Under


:

Steve,

OK, let's split this up to make it easier to debug. And let's also
remove
any reserved word problem by enclosing the word "Type" in square
brackets.

If Nz(Forms!Lanes![Type], "") = "wood" Then
DoCmd.RunMacro "Wood"
Else
DoCmd.RunMacro "Synthetic"
End If

Of course, the spelling of the two macros are correct, aren't they?
"Wood"
and "Synthetic"?

Before running any code, select Compile from the Debug menu, and fix
any
problems that arise from that. Then we can move on.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Graham , When double clicked both macros worked fine. Triedto put
LCase
in
but didn't know where to put the closing bracket . Whe I put it at
the
end
it
did not allow me.
By the way thanks for helping me out.
Steve
Thanks from Down Under


:

Steve,

What happens if you double-click each macro on its own? Do they
complete
successfully?

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


I must be a bit' D' but still the same, this is how it reads
now'
Private Sub Command2_Click()
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro ("Wood")
Else
DoCmd.RunMacro ("Synthetic") (all on one line)
Same error message as before When when I debug what ever action
it
has
done
will be highlighted in yellow, and it is only doing that action
where
as
before it was doing both.
Thanks from Down Under


:

Steve,

Why do you have the If statement enclosed in brackets? Delete
the
outer
brackets:
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro "Wood"
Else
DoCmd.RunMacro "Synthetic"

If that doesn't fix it (and this shouldn't really make any
difference
at
all), but try enclosing the macro names in brackets.
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro("Wood")
Else
DoCmd.RunMacro("Synthetic")

Also just to be sure you don't run into any other problems,
change
the
expression to cater for the fact that users may enter uppercase,
lowercase
or mixed case.
If LCase(Nz(Forms!Lanes!Type, "") = "wood") Then ...

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Thanks Graham, I did as you said and put it all on one
line,BUT,
I
am
now
recieving an error message
Run-time error'2501'
The run macro action was cancelled. I pushed debug and
(If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro
"Wood"
Else
DoCmd.RunMacro "Synthetic") the "DoCmd.RunMacro "Wood"
Else"
is
highlighted in yellow.
Cheers
Steve Lismore NSW

--
Thanks from Down Under


:

Steve,

The following two lines MUST appear on the SAME line!
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro
"Wood"
Else
DoCmd.RunMacro "Synthetic"

There are two ways to write an If..Then statement:
If x = y Then
'blah
Else
'blech
End If

....or...

If x = y Then blah Else blech

Notice the second option does not require an 'End If' clause.
This
option
is
the one I recommended.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Guys Im back,Graham I gave the code a go and It worked
(feel
like a
hero)
but with one small problem, it did both operations.
Here is what the sub looked like.
Private Sub Command2_Click()
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro
"Wood"
Else
DoCmd.RunMacro "Synthetic"


End Sub
Can you see what I've done wrong
Steve
--
Thanks from Down Under


:

Steve,

Create the two macros, MacroA and MacroB, but also create
another
macro,
MacroC. Set MacroC as follows:
Line 1: Condition: [Forms]![form1]![text1]="wood"
Line 1: Action: RunMacro
Line 1: Macro Name: Macro1

Line 2: Condition:
Nz([Forms]![form1]![text1],"")<>"wood"
Line 2: Action: RunMacro
Line 2: Macro Name: Macro2

To view the Conditions column, open the new macro and
select
[Conditions]
from the [View] menu.

Then just run Macro3 whenever you want to do it. For
example,
in
the
OnClick
property of a button, enter:
Macro3.

I cananot use visual basic code
You're already using visual basic code by using the IIf
function.
All
you'd
have to do is to enter the following into a VBA code
module,
for
example,
the Click event of a button
If Nz(Forms!form1!text1,"") = "wood" Then
DoCmd.RunMacro
"Macro1"
Else
DoCmd.RunMacro "Macro2"
....and do away with Macro3 altogether.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


I cananot use visual basic code so I rely on what I know.
I want to run a Macro in a IIf statement
eg
IIf([Forms]![Lanes]![Type]=wood,Run Macro "A",RunMacro
"B")
Could someone please give me a hand
Thanks
 
S

Steve

Graham,
It works a treat, Thank you very much.
I haveStop Macros on all the rest of my macros, is this not required? Should
I remove this from the rest?
regards
Steve
--
Thanks from Down Under


Graham R Seach said:
Steve,

Get rid of the Stop Macro actions.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Steve said:
Morning Graham,
Macro (Wood)
1st Line (Action) Set Value, (Argument) [Forms]![Quoting
Master]![Hidden].Visible,Yes
2nd Line (Action) Stop Macro

Macro (Synthetic)
1st Line (Action) Open Form, (Argument) Synthetic,Form,,,,Normal
2nd Line (Action) Stop Macro

Regads
Steve
--
Thanks from Down Under


Graham R Seach said:
Steve,

OK, what do the individual macros do. I think something's happening in
one
of the macros, so let's start looking there. Write out what they do,
line-by-line.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Evening Graham (I hope you get this in the morning)
This is a direct paste from visual basic.

Private Sub Password_AfterUpdate()
If Nz(Forms!Lanes![Type], "") = "wood" Then
DoCmd.RunMacro "Wood"
Else
DoCmd.RunMacro "Synthetic"
End If

I selected Compile out of the Debug menu and no messages were received.
Operated the control source and the correct macro worked but I also
received
the following error message.
Run-time error 2501:
The RunMacro action was canceled.
Pressed Debug on error message and the macro that had just run was
highlighted in yellow.
I then then removed the [ ] brackets and tested again, with the same
results.
Real frustrating I bet !! especially for you.
Thanks
Steve


--
Thanks from Down Under


:

Steve,

OK, let's split this up to make it easier to debug. And let's also
remove
any reserved word problem by enclosing the word "Type" in square
brackets.

If Nz(Forms!Lanes![Type], "") = "wood" Then
DoCmd.RunMacro "Wood"
Else
DoCmd.RunMacro "Synthetic"
End If

Of course, the spelling of the two macros are correct, aren't they?
"Wood"
and "Synthetic"?

Before running any code, select Compile from the Debug menu, and fix
any
problems that arise from that. Then we can move on.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Graham , When double clicked both macros worked fine. Triedto put
LCase
in
but didn't know where to put the closing bracket . Whe I put it at
the
end
it
did not allow me.
By the way thanks for helping me out.
Steve
Thanks from Down Under


:

Steve,

What happens if you double-click each macro on its own? Do they
complete
successfully?

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


I must be a bit' D' but still the same, this is how it reads
now'
Private Sub Command2_Click()
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro ("Wood")
Else
DoCmd.RunMacro ("Synthetic") (all on one line)
Same error message as before When when I debug what ever action
it
has
done
will be highlighted in yellow, and it is only doing that action
where
as
before it was doing both.
Thanks from Down Under


:

Steve,

Why do you have the If statement enclosed in brackets? Delete
the
outer
brackets:
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro "Wood"
Else
DoCmd.RunMacro "Synthetic"

If that doesn't fix it (and this shouldn't really make any
difference
at
all), but try enclosing the macro names in brackets.
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro("Wood")
Else
DoCmd.RunMacro("Synthetic")

Also just to be sure you don't run into any other problems,
change
the
expression to cater for the fact that users may enter uppercase,
lowercase
or mixed case.
If LCase(Nz(Forms!Lanes!Type, "") = "wood") Then ...

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Thanks Graham, I did as you said and put it all on one
line,BUT,
I
am
now
recieving an error message
Run-time error'2501'
The run macro action was cancelled. I pushed debug and
(If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro
"Wood"
Else
DoCmd.RunMacro "Synthetic") the "DoCmd.RunMacro "Wood"
Else"
is
highlighted in yellow.
Cheers
Steve Lismore NSW

--
Thanks from Down Under


:

Steve,

The following two lines MUST appear on the SAME line!
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro
"Wood"
Else
DoCmd.RunMacro "Synthetic"

There are two ways to write an If..Then statement:
If x = y Then
'blah
Else
'blech
End If

....or...

If x = y Then blah Else blech

Notice the second option does not require an 'End If' clause.
This
option
is
the one I recommended.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Guys Im back,Graham I gave the code a go and It worked
(feel
like a
hero)
but with one small problem, it did both operations.
Here is what the sub looked like.
Private Sub Command2_Click()
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro
"Wood"
Else
DoCmd.RunMacro "Synthetic"


End Sub
Can you see what I've done wrong
Steve
--
Thanks from Down Under


:

Steve,

Create the two macros, MacroA and MacroB, but also create
another
macro,
MacroC. Set MacroC as follows:
Line 1: Condition: [Forms]![form1]![text1]="wood"
Line 1: Action: RunMacro
Line 1: Macro Name: Macro1

Line 2: Condition:
Nz([Forms]![form1]![text1],"")<>"wood"
Line 2: Action: RunMacro
Line 2: Macro Name: Macro2

To view the Conditions column, open the new macro and
select
[Conditions]
from the [View] menu.

Then just run Macro3 whenever you want to do it. For
example,
in
the
OnClick
property of a button, enter:
Macro3.

I cananot use visual basic code
You're already using visual basic code by using the IIf
function.
All
you'd
have to do is to enter the following into a VBA code
 
G

Graham R Seach

Steve,

No, you don't need it, unless for some other purpose, because if there are
no actions after the Stop Macro action, the macro will stop when it finishes
anyway. Macros aren't called "Forrest". :)

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Steve said:
Graham,
It works a treat, Thank you very much.
I haveStop Macros on all the rest of my macros, is this not required?
Should
I remove this from the rest?
regards
Steve
--
Thanks from Down Under


Graham R Seach said:
Steve,

Get rid of the Stop Macro actions.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Steve said:
Morning Graham,
Macro (Wood)
1st Line (Action) Set Value, (Argument) [Forms]![Quoting
Master]![Hidden].Visible,Yes
2nd Line (Action) Stop Macro

Macro (Synthetic)
1st Line (Action) Open Form, (Argument) Synthetic,Form,,,,Normal
2nd Line (Action) Stop Macro

Regads
Steve
--
Thanks from Down Under


:

Steve,

OK, what do the individual macros do. I think something's happening in
one
of the macros, so let's start looking there. Write out what they do,
line-by-line.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Evening Graham (I hope you get this in the morning)
This is a direct paste from visual basic.

Private Sub Password_AfterUpdate()
If Nz(Forms!Lanes![Type], "") = "wood" Then
DoCmd.RunMacro "Wood"
Else
DoCmd.RunMacro "Synthetic"
End If

I selected Compile out of the Debug menu and no messages were
received.
Operated the control source and the correct macro worked but I also
received
the following error message.
Run-time error 2501:
The RunMacro action was canceled.
Pressed Debug on error message and the macro that had just run was
highlighted in yellow.
I then then removed the [ ] brackets and tested again, with the same
results.
Real frustrating I bet !! especially for you.
Thanks
Steve


--
Thanks from Down Under


:

Steve,

OK, let's split this up to make it easier to debug. And let's also
remove
any reserved word problem by enclosing the word "Type" in square
brackets.

If Nz(Forms!Lanes![Type], "") = "wood" Then
DoCmd.RunMacro "Wood"
Else
DoCmd.RunMacro "Synthetic"
End If

Of course, the spelling of the two macros are correct, aren't they?
"Wood"
and "Synthetic"?

Before running any code, select Compile from the Debug menu, and
fix
any
problems that arise from that. Then we can move on.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Graham , When double clicked both macros worked fine. Triedto put
LCase
in
but didn't know where to put the closing bracket . Whe I put it
at
the
end
it
did not allow me.
By the way thanks for helping me out.
Steve
Thanks from Down Under


:

Steve,

What happens if you double-click each macro on its own? Do they
complete
successfully?

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


I must be a bit' D' but still the same, this is how it reads
now'
Private Sub Command2_Click()
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro
("Wood")
Else
DoCmd.RunMacro ("Synthetic") (all on one line)
Same error message as before When when I debug what ever
action
it
has
done
will be highlighted in yellow, and it is only doing that
action
where
as
before it was doing both.
Thanks from Down Under


:

Steve,

Why do you have the If statement enclosed in brackets? Delete
the
outer
brackets:
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro
"Wood"
Else
DoCmd.RunMacro "Synthetic"

If that doesn't fix it (and this shouldn't really make any
difference
at
all), but try enclosing the macro names in brackets.
If Nz(Forms!Lanes!Type, "") = "wood" Then
DoCmd.RunMacro("Wood")
Else
DoCmd.RunMacro("Synthetic")

Also just to be sure you don't run into any other problems,
change
the
expression to cater for the fact that users may enter
uppercase,
lowercase
or mixed case.
If LCase(Nz(Forms!Lanes!Type, "") = "wood") Then ...

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Thanks Graham, I did as you said and put it all on one
line,BUT,
I
am
now
recieving an error message
Run-time error'2501'
The run macro action was cancelled. I pushed debug and
(If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro
"Wood"
Else
DoCmd.RunMacro "Synthetic") the "DoCmd.RunMacro "Wood"
Else"
is
highlighted in yellow.
Cheers
Steve Lismore NSW

--
Thanks from Down Under


:

Steve,

The following two lines MUST appear on the SAME line!
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro
"Wood"
Else
DoCmd.RunMacro "Synthetic"

There are two ways to write an If..Then statement:
If x = y Then
'blah
Else
'blech
End If

....or...

If x = y Then blah Else blech

Notice the second option does not require an 'End If'
clause.
This
option
is
the one I recommended.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia


Guys Im back,Graham I gave the code a go and It worked
(feel
like a
hero)
but with one small problem, it did both operations.
Here is what the sub looked like.
Private Sub Command2_Click()
If Nz(Forms!Lanes!Type, "") = "wood" Then DoCmd.RunMacro
"Wood"
Else
DoCmd.RunMacro "Synthetic"


End Sub
Can you see what I've done wrong
Steve
--
Thanks from Down Under


:

Steve,

Create the two macros, MacroA and MacroB, but also
create
another
macro,
MacroC. Set MacroC as follows:
Line 1: Condition: [Forms]![form1]![text1]="wood"
Line 1: Action: RunMacro
Line 1: Macro Name: Macro1

Line 2: Condition:
Nz([Forms]![form1]![text1],"")<>"wood"
Line 2: Action: RunMacro
Line 2: Macro Name: Macro2

To view the Conditions column, open the new macro and
select
[Conditions]
from the [View] menu.

Then just run Macro3 whenever you want to do it. For
example,
in
the
OnClick
property of a button, enter:
Macro3.

I cananot use visual basic code
You're already using visual basic code by using the IIf
function.
All
you'd
have to do is to enter the following into a VBA code
 

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