Results 1 to 7 of 7
  1. #1
    znxm0i is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2015
    Location
    Oklahoma
    Posts
    11

    Running Combined Modules from Macro

    Hello all,

    A fellow forum member recently compiled some VBA code for me to run from two separate modules and while the code does work I am not sure how to run code via an Access macro. If I try to call the code in the first module via "RUNCODE" it keeps telling me that I have the wrong number of arguments. In the 2nd module, I know I have to change "SUB" to "FUNCTION" in order for it to work. Can anyone please tell me how I would go about combining the two modules and getting them to run via a macro. Below is the code I currently have:

    First module named RptExtras:

    Function GetBoiler(ByVal sFile As String) As String
    '**** Created by someone else
    Dim fso As Object
    Dim ts As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)
    GetBoiler = ts.readall
    ts.Close
    End Function

    Second module named RptAutomation:

    Sub sendForApproval1()
    '*************************************************
    'VBA Code created by Trevor G May 2015
    'Updated from previous version
    '*************************************************
    Dim olApp As Outlook.Application
    Dim olMail As MailItem
    Dim SigString As String
    Dim Signature As String
    Set olApp = New Outlook.Application
    Set olMail = olApp.CreateItem(olMailItem)


    SigString = "C:\Users\con04785\AppData\Roaming\Microsoft\S igna tures\Nina.txt"
    If Dir(SigString) <> "" Then
    Signature = GetBoiler(SigString)
    Else
    Signature = ""
    End If
    With olMail
    .To = "nina@email.com"
    .Subject = Format(Date, "dd-mmm-yyyy") & " Daily Report"
    .Body = "Attached is the latest report update." & vbCr & vbCr & _
    "Thank you." & vbCr & _
    "" & vbCr & _
    "Regards" & Signature

    .Attachments.Add "C:\Users\con04785\Desktop\Daily Protocol Status.pdf"
    .Display 'Change to Send once you are happy this is working for you.
    End With
    Set olMail = Nothing
    Set olApp = Nothing
    End Sub

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    The macro should call just the sendForApproval procedure. The sendForApproval procedure calls the GetBoiler procedure.

    NOTE: deleted duplicate thread
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    znxm0i is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2015
    Location
    Oklahoma
    Posts
    11
    June,

    I am a novice Access user, thank you so very much for helping me with this. It works like a charm. Now next step is to figure out how to get it to run automatically via MS-Task Scheduler, any ideas?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    I use a VBScript that opens Access database, runs procedure, closes db.

    Dim accessApp
    If (Month(Date()) >= 6 And Month(Date()) <= 9) Or ((Month(Date()) <= 5 Or Month(Date()) >= 10) And Day(Date()) < 8) Then
    set accessApp = CreateObject("Access.Application")
    accessApp.OpenCurrentDataBase("path to db\db.accdb")
    accessApp.Run "ConstructionExtract"
    accessApp.Quit
    set accessApp = nothing
    End If

    Task runs the VBScript file as scheduled.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    znxm0i is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2015
    Location
    Oklahoma
    Posts
    11

    Task Scheduler Partially Working

    Thank you June7 for providing this script. I was finally able to get MS-Task Scheduler to launch Access and open my database by using the following instructions found on this forum:

    then in Task Scheduler:
    In the Action section
    Select the Action: Start a program
    Under Settings
    Program/script: "C:\Program Files (x86)\Microsoft Office\Office14\MSACCESS.EXE"
    Add arguments: "\\File02\usfs\Crystal and Excel Reports - Phoenix\CrystalReports\Memberships\Memberships.acc db"
    Start in: C:\Program Files (x86)\Microsoft Office

    However, if I attempt to add the switch "/x DailyProtocolReport" within the quotes immediately following the database name ending in .accdb Access does not work, all it does is just hangs. Is there a way for me to launch get my Access macro "DailyProtocolReport" to run once the Access database opens via Task Scheduler?

    I tried earlier running VB script but I would have to provide written justification as to why I need this script to run on a company server. I am a Administrative Assistant who is simply trying to automate her reporting process so that a daily report is sent without my manual intervention. With your help and the help of others, I've come this far in getting the Access macro to work and Task Scheduler to run, I just need to know how to get everything to fire at once.

    Any other suggestions

    Quote Originally Posted by June7 View Post
    I use a VBScript that opens Access database, runs procedure, closes db.

    Dim accessApp
    If (Month(Date()) >= 6 And Month(Date()) <= 9) Or ((Month(Date()) <= 5 Or Month(Date()) >= 10) And Day(Date()) < 8) Then
    set accessApp = CreateObject("Access.Application")
    accessApp.OpenCurrentDataBase("path to db\db.accdb")
    accessApp.Run "ConstructionExtract"
    accessApp.Quit
    set accessApp = nothing
    End If

    Task runs the VBScript file as scheduled.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    AFAIK, must be VBA procedure, not macro. I don't use macros.

    I've never used a switch.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    znxm0i is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2015
    Location
    Oklahoma
    Posts
    11
    I finally got it to work. Had to place the switch outside the quotes after calling the database.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Running macro once per year
    By wlkr.jk in forum Macros
    Replies: 4
    Last Post: 06-12-2014, 01:08 PM
  2. Replies: 2
    Last Post: 01-08-2013, 03:28 PM
  3. Can't see my modules as option run in a Macro
    By Meteo in forum Programming
    Replies: 4
    Last Post: 10-26-2012, 02:43 PM
  4. running macro in another DB
    By AdrianoG87 in forum Import/Export Data
    Replies: 1
    Last Post: 09-30-2011, 12:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums