Results 1 to 4 of 4
  1. #1
    jairgarza is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Oct 2017
    Posts
    18

    run report and save automatically VBS

    Hi there,

    I have a Form (AP Reports) that has a button that opens a Report (OF Specific), which is based on a Query that asks for input (Start Date). What I want to do is once the button is clicked to get the report to run, query will ask input date and save the report.. here's what I have, it works it is just that you need to click the save button (Command13_Click) to get it to save, I want it to be with out the click... any ideas?

    Private Sub Command13_Click()
    Dim RName, RPath, RSaveas, GetUsername As String


    Dim dateadded As String




    GetUsername = Environ("username")
    dateadded = Format([Start Date], "mm-dd-yy")
    RName = "OF " & dateadded & ".pdf"
    RPath = "C:\Users" & GetUsername & "\Desktop"
    RSaveas = RPath & RName
    MsgBox "The report will be saved in your Desktop as: " & Chr(13) & Chr(10) & RName
    DoCmd.OutputTo objecttype:=acOutputReport, Objectname:="OF Specific", outputformat:=acFormatPDF, Outputfile:=RSaveas, autostart:=False, outputquality:=acExportQualityPrint
    DoCmd.Close
    DoCmd.OpenForm "AP Reports", , acDialog
    End Sub

  2. #2
    orange's Avatar
    orange is online now Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,850
    This does not do what you think

    Dim RName, RPath, RSaveas, GetUsername As String

    With Access you must explicitly Dim your variable data types. If you do not they will automatically be Variants.

    So Dim RName as String, RPath as String OR
    Dim RName as String
    Dim RPath as String

    You're using a button --not sure what other event(s) you could use.

  3. #3
    jairgarza is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Oct 2017
    Posts
    18
    Thanks for your reply orange, even if is not what I asked

    I am not sure what you are trying to teach me, if I do not declare them, process stops (debug)....

    What I am trying to do is what the button does, but sort of "on load" yet on load does not work, it crashes... it errors on Objectname ... "this action cannot be carried out while processing a form or report event" - I do need to use value in Expr1 (Prints on report) box as the Date since it will not take the one from the Query... any suggestions?

    Again, thanks for trying to help

  4. #4
    orange's Avatar
    orange is online now Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,850
    My previous post was meant to show you an error in your Dim statement.
    You must explicitly dim your variables; else they re variant data type(default).

    The last line
    Code:
    You're using a button --not sure what other event(s) you could use
    was specific to your issue. You are using a button, what else (other than click) can/did you think you could do to make something happen?
    Other events for command button

    You could have a Form and have a calendar or a list of Dates to be used with your report.

    You could select the appropriate date, then click a Make Report button that would
    Open the Report and pass an Open argument (the Date) to the Report. (requires coding)

    There is an example here.

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

Similar Threads

  1. Replies: 4
    Last Post: 04-26-2016, 08:41 AM
  2. Replies: 2
    Last Post: 07-15-2015, 08:35 PM
  3. Replies: 3
    Last Post: 12-12-2012, 01:13 AM
  4. Replies: 1
    Last Post: 08-31-2012, 01:47 PM
  5. Replies: 10
    Last Post: 06-20-2012, 09:50 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