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