Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Multiple macros run if criteria met...

Posted on 2004-09-30
12
Medium Priority
?
580 Views
Last Modified: 2012-06-21
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
0
Comment
Question by:Lapchien
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
  • +1
12 Comments
 
LVL 8

Expert Comment

by:JonoBB
ID: 12188043
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
 
LVL 41

Accepted Solution

by:
shanesuebsahakarn earned 2000 total points
ID: 12188056
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
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 12188057
Also - why use macros at all, why not just use VBA to do whatever it is that your macros do?
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 34

Expert Comment

by:flavo
ID: 12188063
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
 
LVL 34

Expert Comment

by:flavo
ID: 12188066
ahh... stDocName  the Access VB "builder"... Dont listen to it :-)

Good point Shane
0
 

Author Comment

by:Lapchien
ID: 12188182
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
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 12188194
Dump the stDocName lines completely and just make the last line:
DoCmd.RunMacro "startup"
0
 

Author Comment

by:Lapchien
ID: 12188212
Thanks shanesuebsahakarn  - btw what does the stDocName do?
0
 
LVL 8

Expert Comment

by:JonoBB
ID: 12188216
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
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 12188263
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
 
LVL 8

Expert Comment

by:JonoBB
ID: 12188273
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
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 12188311
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

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question