+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    08-06-2007
    Posts
    99

    View Report (With Excel) - vba code?

    I have a database that currently when you click the button on the form, it opens the report "rpt_Test".

    I have to then manually view it with excel and save it.

    I'm looking for a code that will do the following:

    1) Click the button on form = msgbox ("View report or export?") vbyesno
    2) Yes = View report
    2a) No = Export into S:\Testing\TestReport.xls
    2b) msgbox ("Successfully exported!")
    3) exit report view and just show form

    I tried looking through the macro commands and couldn't find anything, so i'm ok using VBA instead

    Thanks for all the help!
    Last edited by adgjqetuo; 11-20-2009 at 08:49 AM.

  2. #2
    Forum Moderator Richard Buttrey's Avatar
    Join Date
    02-15-2008
    Location
    Grappenhall, UK
    MS-Off Ver
    Excel for Windows & Mac - all versions.
    Posts
    5,823

    Re: View Report (With Excel) - vba code?

    Hi,

    Is "rpt_test" a workbook, worksheet or range?

    Rgds
    Richard Buttrey

    If this was useful then please rate it appropriately.

    Click the small star icon at the bottom left of my post.

  3. #3
    Forum Moderator ConneXionLost's Avatar
    Join Date
    03-11-2009
    Location
    Victoria, Canada
    MS-Off Ver
    2003 & 2010
    Posts
    1,791

    Re: View Report (With Excel) - vba code?

    Hi adgjqetuo,

    Here are the VBA DoCmd codes you could use if you went with two buttons:

    To view the report:
    Code:
    DoCmd.OpenReport "rpt_Test", acViewNormal, acPreview
    To export the report to a file:
    Code:
    DoCmd.OutputTo ObjectType:=acOutputReport, _
        ObjectName:="rpt_Test", _
        OutputFormat:=acFormatXLS, _
        OutputFile:="S:\Testing\TestReport.xls", _
        AutoStart:=True
    Cheers,
    Docendo discimus.

    Please consider:
    • Thanking those who helped you. Click the reputation icon in the contributor's post and add Reputation.
    • Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  4. #4
    Registered User
    Join Date
    08-06-2007
    Posts
    99

    Re: View Report (With Excel) - vba code?

    Quote Originally Posted by ConneXionLost View Post
    Hi adgjqetuo,

    Here are the VBA DoCmd codes you could use if you went with two buttons:

    To view the report:
    Code:
    DoCmd.OpenReport "rpt_Test", acViewNormal, acPreview
    To export the report to a file:
    Code:
    DoCmd.OutputTo ObjectType:=acOutputReport, _
        ObjectName:="rpt_Test", _
        OutputFormat:=acFormatXLS, _
        OutputFile:="S:\Testing\TestReport.xls", _
        AutoStart:=True
    Cheers,
    Thanks for the response! The export code works perfectly only it opens the excel file too. I want it to export "behind the scenes" and not actually open - just save. I tried turning off notifications but that didn't work. Any ideas?

    Would turning auto start to "false" do the trick? I didn't think to try that earlier.

    Also, what's the access vb code for yes no message box? Is it the same as excel?

    IE:
    if msgbox ("test", vb yesno) = vbyes then
    <code>
    else
    <code>
    end if
    Last edited by adgjqetuo; 11-19-2009 at 02:20 AM.

  5. #5
    Forum Moderator ConneXionLost's Avatar
    Join Date
    03-11-2009
    Location
    Victoria, Canada
    MS-Off Ver
    2003 & 2010
    Posts
    1,791

    Re: View Report (With Excel) - vba code?

    Hi adgjqetuo,

    Try changing:

    AutoStart:=True

    to:

    AutoStart:=False

    Cheers,
    Docendo discimus.

    Please consider:
    • Thanking those who helped you. Click the reputation icon in the contributor's post and add Reputation.
    • Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  6. #6
    Forum Moderator ConneXionLost's Avatar
    Join Date
    03-11-2009
    Location
    Victoria, Canada
    MS-Off Ver
    2003 & 2010
    Posts
    1,791

    Re: View Report (With Excel) - vba code?

    Hi adgjqetuo,

    You can use a MsgBox using the syntax described here:

    MsgBox

    But you may prefer to build your own form for this purpose.

    Cheers,
    Docendo discimus.

    Please consider:
    • Thanking those who helped you. Click the reputation icon in the contributor's post and add Reputation.
    • Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  7. #7
    Registered User
    Join Date
    08-06-2007
    Posts
    99

    Re: View Report (With Excel) - vba code?

    The codes you provided worked perfectly!

    The msgbox I coded above worked fine. (I'm an excel guy and wasn't sure if that code was interchangable. but apparently it is)

    Thank you!!!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0