Results 1 to 5 of 5
  1. #1
    kmoore@bmss.com is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Apr 2015
    Posts
    2

    Run Macro that uses one query instead of multiple ones

    I have at least 45 queries that I run, the only difference is that the employee number in the criteria.



    I run a macro that runs the query and emails it to the persons email address,
    is it possible to have a macro that runs one query but runs it for each employee?
    Example of Employee 41 in query below.

    Click image for larger version. 

Name:	Criteria.JPG 
Views:	12 
Size:	11.6 KB 
ID:	20402

    This is the macro and how I run each query.

    Click image for larger version. 

Name:	Macro.JPG 
Views:	12 
Size:	40.9 KB 
ID:	20403

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    I have a list box of all the persons to email: name, email
    this code scans the list and sends

    Code:
    '------------
    Public Sub ScanAndEmail()
    '------------
    Dim vTo, vSubj, vBody, vRpt
    Dim vFilePath
    dim i as integer
    
    
    vRpt = "rReport1"
    vBody = "body of email"
    vSubj = vRpt
    vFilePath = ""  'path of the snapshot or XL or PdF
    
    
         'scan the list box
    For i = 0 To lstEAddrs.ListCount - 1
       lstEAddrs.itemdata = i
       vTo = lstEAddrs.Column(2)
         
       DoCmd.SendObject acSendReport, vRpt, acFormatPDF, vTO, , , vSubj, vBody
    Next
    End Sub

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    This requires VBA code. One approach is to loop through a recordset of the email addresses. Common topic. https://www.accessforums.net/program...ook-21903.html
    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.

  4. #4
    kmoore@bmss.com is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Apr 2015
    Posts
    2
    Thank you for the response, let me better explain my issue, I have multiple queries that I want to change to one query, the only think different is the criteria in the query, the EMPNUM is different for all employees, I can write a macro sending email to each person just using one query if I can just change the criteria in each EmailDatabaseObject command

  5. #5
    NTC is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Posts
    2,392
    they understood your issue. yes it can be done with 1 query but no it cannot be done using a macro - only vba has looping which is what you need.

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

Similar Threads

  1. Replies: 3
    Last Post: 01-27-2015, 08:34 AM
  2. Replies: 1
    Last Post: 01-07-2015, 12:04 PM
  3. Replies: 7
    Last Post: 02-26-2013, 02:26 PM
  4. Replies: 2
    Last Post: 05-05-2012, 02:34 AM
  5. Import multiple Text files with a Macro
    By ArchMap in forum Access
    Replies: 3
    Last Post: 07-01-2011, 04:56 PM

Tags for this Thread

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