Export report by filedialog

S

Seansan

Hi there,

I am trying to write some code to export a report to file (preferred RTF).

Ho do I save the current report? VBA help tells me to leave the second
argument blanc, but an error is raised

DoCmd.OutputTo acOutputReport, , acFormatRTF, file_loc, True

Any help appreciated

Thx, Sean
 
T

Tom Wickerath

Hi Sean,
VBA help tells me to leave the second argument blank, but an error is raised

It says to leave the second argument blank if you want to export the active
object. Trouble is, your report is likely not active at the time you are
running this code. Try the following procedure instead:

Sub ExportReportAsRTF()
On Error GoTo ProcError

DoCmd.OutputTo ObjectType:=acOutputReport, ObjectName:="rptArtists", _
OutputFormat:=acFormatRTF, AutoStart:=False

ExitProc:
Exit Sub
ProcError:
Select Case Err.Number
Case 2501 ' User clicked on cancel
Case Else
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure ExportReportAsRTF..."
End Select
Resume ExitProc
End Sub

or

Sub ExportReportAsRTF2()
On Error GoTo ProcError

DoCmd.OutputTo ObjectType:=acOutputReport, ObjectName:="rptArtists", _
OutputFormat:=acFormatRTF, OutputFile:="Test.rtf", _
AutoStart:=False

ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure ExportReportAsRTF..."
Resume ExitProc
End Sub

These subroutines can easily be modified to pass in the name of the report
as a parameter, instead of hard coding. Your choice. Be aware that exporting
reports in RTF format can leave a lot to be desired. This is not a WYSIWYG
export. For example, lines and checkboxes are not exported correctly.

Tom
________________________________________

:

Hi there,

I am trying to write some code to export a report to file (preferred RTF).

Ho do I save the current report? VBA help tells me to leave the second
argument blanc, but an error is raised

DoCmd.OutputTo acOutputReport, , acFormatRTF, file_loc, True

Any help appreciated

Thx, Sean
 
S

Seansan

Thx, this works, but not a 100%. The thing is that I call a report from a
form with certain WHERE or FILTER statements. I want to export the result.
The code now exports the whole report, instead of the choosen selection

any ideas? Is it possible to have a custom popup/message/button on a report
that can EXPORT the current object?

gr, Sean

<code>

Private Sub exportRFCs_Click()
Dim file_loc As String: file_loc = ""
Dim strFilter As String: strFilter = ""
strFilter = ahtAddFilterItem(strFilter, "Rapporten (*.doc)", "*.rtf")
file_loc = ahtCommonFileOpenSave(OpenFile:=False, _
Filter:=strFilter, _
Flags:=ahtOFN_OVERWRITEPROMPT Or
ahtOFN_READONLY, _
DefaultExt:="rtf", _
DialogTitle:="Export Rapport")
If Not (IsNull(file_loc) Or file_loc = "") Then
DoCmd.OutputTo acOutputReport, "RFCsInBehandeling", acFormatRTF,
file_loc, False
End If

I want to apply the same filter to "RFCsInBehandeling" as I would when I
show the report in printmode
 
T

Tom Wickerath

Hi Sean,

I was headed out the door, to go to work, when I just noticed your reply. I
won't be able to get back to this thread for approx. the next 10 hours or so.
If anyone else wants to step in and answer, please do so.

Tom
___________________________________________

:

Thx, this works, but not a 100%. The thing is that I call a report from a
form with certain WHERE or FILTER statements. I want to export the result.
The code now exports the whole report, instead of the choosen selection

any ideas? Is it possible to have a custom popup/message/button on a report
that can EXPORT the current object?

gr, Sean

<code>

Private Sub exportRFCs_Click()
Dim file_loc As String: file_loc = ""
Dim strFilter As String: strFilter = ""
strFilter = ahtAddFilterItem(strFilter, "Rapporten (*.doc)", "*.rtf")
file_loc = ahtCommonFileOpenSave(OpenFile:=False, _
Filter:=strFilter, _
Flags:=ahtOFN_OVERWRITEPROMPT Or
ahtOFN_READONLY, _
DefaultExt:="rtf", _
DialogTitle:="Export Rapport")
If Not (IsNull(file_loc) Or file_loc = "") Then
DoCmd.OutputTo acOutputReport, "RFCsInBehandeling", acFormatRTF,
file_loc, False
End If

I want to apply the same filter to "RFCsInBehandeling" as I would when I
show the report in printmode
 
G

George Nicholson

One approach would be to have your form set a global string variable(s) with
your conditions and then, in Report_Open, check to see if conditions have
been specified and, if so, apply them. (Set the variables to "" on
Report_Close).

Then, no matter how the report is opened, it will apply the current
conditions.
 
T

Tom Wickerath

Hi George,

Thanks for stepping in.

Sean: Does George's suggestion work for you?


Tom
_____________________________________


One approach would be to have your form set a global string variable(s) with
your conditions and then, in Report_Open, check to see if conditions have
been specified and, if so, apply them. (Set the variables to "" on
Report_Close).

Then, no matter how the report is opened, it will apply the current
conditions.
 
S

Seansan

Tom and George,

globals are not my strongest subject, but I'll try to figure this one out!

Thx, Sean
 
S

Seansan

my code, for future reference

<calling program>
Private Sub exportRFCs_Click()
Dim file_loc As String: file_loc = ""
Dim strFilter As String: strFilter = ""
Dim file_name As String: file_name = "My default file name"
If Not IsNull(SEL_OWNER.Value) Then
file_name = file_name + " " + SEL_OWNER.Value
End If
global_fltr = buildfltr
global_query = getdataset
strFilter = ahtAddFilterItem(strFilter, "Rapporten (*.rtf)")
file_loc = ahtCommonFileOpenSave(OpenFile:=False, _
Filter:=strFilter, _
Flags:=ahtOFN_OVERWRITEPROMPT Or
ahtOFN_READONLY, _
DefaultExt:="rtf", _
DialogTitle:="Export Rapport", _
FileName:=file_name)
If Not (IsNull(file_loc) Or file_loc = "") Then
DoCmd.OutputTo acOutputReport, "RFCsInBehandeling", acFormatRTF,
file_loc, False
End If
End Sub

<in report>
Private Sub Report_Open(Cancel As Integer)
If (global_query = "") Then
MsgBox "No dataset defined, exiting"
Exit Sub
End If
Me.RecordSource = global_query
Me.OrderBy = "RFC_IA_Status ASC"
If (global_fltr = "") Then Exit Sub
DoCmd.ApplyFilter , global_fltr
End Sub
 
Top