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
Solved

Multiple macros run if criteria met...

Posted on 2004-09-30
12
566 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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

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…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

809 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