Welcome to the Excel Forum

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.

Please Register to Remove these Ads

Please Register to Remove these Ads



Reply
  #1  
Old 11-18-2009, 11:41 AM
adgjqetuo adgjqetuo is offline
Registered User
 
Join Date: 06 Aug 2007
Posts: 87
adgjqetuo is becoming part of the community
View Report (With Excel) - vba code?

Please Register to Remove these Ads

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 07:49 AM.
Reply With Quote
  #2  
Old 11-18-2009, 11:48 AM
Richard Buttrey's Avatar
Richard Buttrey Richard Buttrey is offline
Forum Moderator
 
Join Date: 15 Feb 2008
Location: Grappenhall, UK
MS Office Version:Excel for Windows 2003, 2007, for Mac 2004, 2008
Posts: 3,351
Richard Buttrey is very confident of their ability Richard Buttrey is very confident of their ability Richard Buttrey is very confident of their ability
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 balance scales icon in the grey (or gray if you inhabit our former colony across the pond ) bar at the top of my post.
Reply With Quote
  #3  
Old 11-18-2009, 12:54 PM
ConneXionLost's Avatar
ConneXionLost ConneXionLost is offline
Valued Forum Contributor
 
Join Date: 11 Mar 2009
Location: Victoria, Canada
MS Office Version:2003
Posts: 576
ConneXionLost is attaining expert status ConneXionLost is attaining expert status
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.
Reply With Quote
  #4  
Old 11-19-2009, 01:07 AM
adgjqetuo adgjqetuo is offline
Registered User
 
Join Date: 06 Aug 2007
Posts: 87
adgjqetuo is becoming part of the community
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 01:20 AM.
Reply With Quote
  #5  
Old 11-19-2009, 01:15 AM
ConneXionLost's Avatar
ConneXionLost ConneXionLost is offline
Valued Forum Contributor
 
Join Date: 11 Mar 2009
Location: Victoria, Canada
MS Office Version:2003
Posts: 576
ConneXionLost is attaining expert status ConneXionLost is attaining expert status
Re: View Report (With Excel) - vba code?

Hi adgjqetuo,

Try changing:

AutoStart:=True

to:

AutoStart:=False

Cheers,
__________________
Docendo discimus.
Reply With Quote
  #6  
Old 11-19-2009, 01:25 AM
ConneXionLost's Avatar
ConneXionLost ConneXionLost is offline
Valued Forum Contributor
 
Join Date: 11 Mar 2009
Location: Victoria, Canada
MS Office Version:2003
Posts: 576
ConneXionLost is attaining expert status ConneXionLost is attaining expert status
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.
Reply With Quote
  #7  
Old 11-20-2009, 07:49 AM
adgjqetuo adgjqetuo is offline
Registered User
 
Join Date: 06 Aug 2007
Posts: 87
adgjqetuo is becoming part of the community
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!!!
Reply With Quote


Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Forum Jump