Solved

Multiple macros run if criteria met...

Posted on 2004-09-30
12
562 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
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…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

803 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