Multiple macros run if criteria met...

I have a command button that essentially saves a record and opens a new blank form.  However, when the user clicks this button I have a bit of code that checks for certain checkboxes and if they are true or false it acts accordingly.  Can anyone improve my code..:?

Private Sub Command137_Click()
On Error GoTo Err_Command137_Click
DoCmd.RunCommand acCmdSaveRecord

    Dim stDocName As String
   
    stDocName = "haukpolicyemailer"
    If Me.hauk_sold.Value = True Then DoCmd.RunMacro stDocName
   
    stDocName = "hauk_hotleader"
    If Me.hauk_sold.Value = True Then DoCmd.RunMacro stDocName

    stDocName = "hauk_appender"
    If Me.hauk_hotlead.Value = True Then DoCmd.RunMacro stDocName
   
    stDocName = "startup"
    DoCmd.RunMacro stDocName

Exit_Command137_Click:
    Exit Sub

Err_Command137_Click:
    MsgBox Err.Description
    Resume Exit_Command137_Click
End Sub


At the moment I think it just runs all the macros, irrespective of whether hauk_hotlead or hauk_sold or true or false!

Thanks
Lap
LapchienDirectorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JonoBBCommented:
Hmmm,

Try this
   
    stDocName = "haukpolicyemailer"
    If Me.hauk_sold = True
        Then DoCmd.RunMacro stDocName
    end if

Do the same for the others and see how it goes
0
shanesuebsahakarnCommented:
You know, there's no real need for the stDocName part. You'd only generally use that if you needed to reference the same document more than once. Try something like this:

If Me!hauk_sold=True Then
   DoCmd.RunMacro "haukpolicyemailer"
   DoCmd.RunMacro "haukhotlead"
End If
If Me!hauk_hotlead=True Then DoCmd.RunMacro "hauk_appender"
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
shanesuebsahakarnCommented:
Also - why use macros at all, why not just use VBA to do whatever it is that your macros do?
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

flavoCommented:
yes, VBA does have a bug that occurs if you keep all of the If.. then.. else statement in 1 line.

Do as JonoBB  recommends

Only trying to give you the reason why your approach didnt work, pls dont accpet me as the answer.

dave
0
flavoCommented:
ahh... stDocName  the Access VB "builder"... Dont listen to it :-)

Good point Shane
0
LapchienDirectorAuthor Commented:
ok, thanks - so I have:

    Dim stDocName As String
   
    If Me!hauk_sold = True Then
    DoCmd.RunMacro "haukpolicyemailer"
    DoCmd.RunMacro "hauk_appender"
    End If
    If Me!hauk_hotlead = True Then
    DoCmd.RunMacro "hauk_hotleader"
    End If

    stDocName = "startup"
    DoCmd.RunMacro stDocName

0
shanesuebsahakarnCommented:
Dump the stDocName lines completely and just make the last line:
DoCmd.RunMacro "startup"
0
LapchienDirectorAuthor Commented:
Thanks shanesuebsahakarn  - btw what does the stDocName do?
0
JonoBBCommented:
Sorry Shane, not that I really care about the points, but I have seen you complaining when the same thing has happened to you, so I cant resist but quote from your signature:

Plagiarism is a crime. If you wish to post in a question with a correction to another expert's answers, then do so by all means but indicate that you are only providing a correction to another post. Deliberately doing so without addinng a note is rude, a violation of professional courtesy and an attempt to steal credit for another person's work. If you don't want it done to you then DON'T DO IT TO SOMEONE ELSE. I will show you the same courtesy (or lack thereof) that you show me.
0
shanesuebsahakarnCommented:
Yes - but I hadn't seen your post when I posted mine (at 9.48AM, two minutes after your post). It's not like I did this deliberately or an hour later or anything like that.

If you're upset about not receiving the points for this question, I don't mind if you want to have the question reopened so that Lapchien can accept your answer instead.
0
JonoBBCommented:
I never suspected that you did this deliberatly, and I am not upset :)

I just thought it quite funny, after having read your sig.

As I said, I dont mind the points, so no need to re-open the question
0
shanesuebsahakarnCommented:
The message in my profile was referring to persons who post an hour or more after the solution offered and using exactly the same code (sometimes not even re-worded). The excuse that they didn't see the previous post just doesn't cut it - especially when it's patently obvious that they posted their "solution" in response to my post (as the questioner hadn't come back to say anything yet).
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.