Results 1 to 5 of 5
  1. #1
    daddylongtoe is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    7

    Combining events

    Hi

    I have added 2 command buttons to a form where you enter the details of a purchase order, 1 to print the purchase order report and 1 to send it to file. These both work individually, but I want to know if I can combine the print & save events so the user only has to press one button.

    Also, on the send to file button I would like to know what command is required to predefine the directory that the file is saved to. I have specified the filename and the file type, which both work as I'd expect. It would also be useful if the file was automatically saved so the user isn't required to click OK to confirm the save.

    This is the code currently in use:

    Private Sub PrintOrder_Click()
    On Error GoTo Err_PrintOrder_Click
    Dim stDocName As String
    stDocName = "Purchase Order"
    DoCmd.OpenReport stDocName, acNormal
    Exit_PrintOrder_Click:


    Exit Sub
    Err_PrintOrder_Click:
    MsgBox Err.Description
    Resume Exit_PrintOrder_Click

    End Sub
    Private Sub SaveOrder_Click()
    On Error GoTo Err_SaveOrder_Click
    Dim stDocName As String
    stDocName = "M" & [PurchaseOrderID]
    DoCmd.OutputTo acReport, stDocName, acFormatRTF
    Exit_SaveOrder_Click:
    Exit Sub
    Err_SaveOrder_Click:
    MsgBox Err.Description
    Resume Exit_SaveOrder_Click

    End Sub


    In summary, I'm hoping to create a button that will print the purchase order and automatically save a copy in a predetermined folder with only one click of a button. Any help will be greatly appreciated!

    Thanks

    Steve

  2. #2
    NTC is offline VIP
    Windows Vista Access 2007
    Join Date
    Nov 2009
    Posts
    2,392
    sure; in one of the button - go to it's vba code - copy the open argument to your clipboard; then open the other button and paste that code in there.

  3. #3
    daddylongtoe is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    7

    Question to clarify...

    Thanks for the response, but can you tell me which part of the argument needs to be copied? I have tried a few variations, but I get issues with unrecognized commands.

    The button commands are all listed on one page as they are on the same form, seperated only by lines as illustrated below:

    -----------------------------------------------------------
    Private Sub PrintOrder_Click()
    On Error GoTo Err_PrintOrder_Click

    Dim stDocName As String

    stDocName = "Purchase Order"
    DoCmd.OpenReport stDocName, acNormal

    Exit_PrintOrder_Click:
    Exit Sub

    Err_PrintOrder_Click:
    MsgBox Err.Description
    Resume Exit_PrintOrder_Click

    End Sub
    ------------------------------------------------------------
    Private Sub SaveOrder_Click()
    On Error GoTo Err_SaveOrder_Click

    Dim stDocName As String

    stDocName = "Purchase Order"
    DoCmd.OutputTo acReport, stDocName, acFormatRTF

    Exit_SaveOrder_Click:
    Exit Sub

    Err_SaveOrder_Click:
    MsgBox Err.Description
    Resume Exit_SaveOrder_Click

    End Sub
    ------------------------------------------------------------

    I assume you can only use one name for the event procedure for one button. Thanks again for your help.

    Steve

  4. #4
    NTC is offline VIP
    Windows Vista Access 2007
    Join Date
    Nov 2009
    Posts
    2,392
    copy:

    Dim stDocName As String
    stDocName = "Purchase Order"
    DoCmd.OpenReport stDocName, acNormal

    directly above or below:

    Dim stDocName As String
    stDocName = "Purchase Order"
    DoCmd.OutputTo acReport, stDocName, acFormatRTF

    whichever is below will be 'on top' in terms of the user experience...you'll have to shrink it to see the one below....

  5. #5
    daddylongtoe is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    7

    Thanks

    Great advice, all working as I wanted. The only thing I had to do was drop one instance of Dim stDocName As String as it was duplicating the declaration.

    You saved me a lot of time - thanks!

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

Similar Threads

  1. object or class does not support the set of events
    By couch potato in forum Programming
    Replies: 2
    Last Post: 03-20-2010, 08:55 AM
  2. Events Procedure Question..
    By Procom Webserve in forum Access
    Replies: 16
    Last Post: 12-07-2009, 10:13 AM
  3. form events
    By EinSpringfielder in forum Programming
    Replies: 1
    Last Post: 08-26-2009, 11:01 AM
  4. Timed events
    By summitrider in forum Access
    Replies: 2
    Last Post: 08-14-2008, 04:38 PM
  5. Events Report, please help!
    By Suzan in forum Reports
    Replies: 3
    Last Post: 04-19-2006, 01:11 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