Results 1 to 4 of 4
  1. #1
    csn102 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Nov 2015
    Location
    Phoenix, AZ
    Posts
    1

    Automating Button Clicking

    Greetings,



    In my database, I have a split form that displays the results of a query. Those results can vary in number based on the parameters entered into my query. Now, I have a button that, when clicked, takes records from that query and sends it as an email report. This I have down and it works well. However, based on the results of the initial query, I may have to click the email button several times to 50+. I would like to automate the button click so that when clicked, it activates a macro (or vba) that collects the data for the email report and sends it.

    So far, I haven't had much luck. The most I've been able to find is:
    Code:
     public function clickButton(btn as Control) as boolean  btn.value = true
    end function
    but I haven't been able to get it to work successfully.

    Is this doable? If so, what am I missing?

  2. #2
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    Word mail merge could be an option. Use the query as a data source and send out as many as you like

  3. #3
    bigot is offline Advanced...ish
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2014
    Posts
    37
    I would suggest doing it differently (I'll explain that), but I'll also show you how to do it your way.

    Your way:
    The button's click event handler is actually a function you can call! For example, if the VBA for the button is:
    Code:
    Private Sub Command1_Click()
        'code that does email stuff is here
    End Sub
    Then you can simply call "Command1_Click". However, if you have a continuous form, and you have multiple instances of the same button, it won't work as desired.

    EDIT:
    On second thought, if this is a continuous form, calling "Command1_Click" will call the first instance. So if you remove the row after the email is sent, then you can add a button to the header ("Mail all" or something):
    Code:
    Private Sub cmdMailAll_Click()
        While Form.Recordset.RecordCount > 0
            cmdMailReport_Click
            Form.Requery
        Wend
    End Sub
    I know I already said this, but just to be safe: in order for this to work, you MUST remove the row after the email is sent. Otherwise you will spam the first one forever. Also Form.Requery is required (same reason).
    /EDIT


    My Suggestion:
    Rewrite the mail function to take a parameter that indicates which report to mail (use a primary key or other unique identifier). Example:
    Code:
    Sub MailDaReportYo(ReportID as Integer)
    and then just call that in a loop that iterates all the rows in your split form.

    Hope that helps. If you provide more detail or a database file, I can help further.






    EDIT #2:
    Lol, so many edits.
    Quote Originally Posted by csn102 View Post
    Code:
     public function clickButton(btn as Control) as boolean  btn.value = true
    end function
    This might work (untested):
    Code:
    public function clickButton(btn as Control) as boolean
    Run( btn.Name & "_Click" )
    end function
    Simply takes your button's name and adds "_Click" to it, then runs that as a function.
    /EDIT

  4. #4
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 8 Access 2013
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    This can be done it Acces with a little VBA code to use a recordset to loop through the records and send each email.

    I have created an example that create a PDF for each record. It would be very easy to add the lines of code to send it as an email.

    See: Batch Printing and Save As PDF (Click Here)

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

Similar Threads

  1. Replies: 2
    Last Post: 09-15-2015, 03:08 AM
  2. Replies: 3
    Last Post: 11-25-2014, 11:13 AM
  3. Replies: 2
    Last Post: 02-23-2012, 07:21 PM
  4. Replies: 7
    Last Post: 12-17-2011, 08:06 PM
  5. Comments when clicking a button
    By Juan4412 in forum Programming
    Replies: 4
    Last Post: 06-23-2011, 04:34 PM

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