Solved

Multiple macros run if criteria met...

Posted on 2004-09-30
12
553 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
  • 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 500 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

760 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now