Connecting Tech Pros Worldwide Forums | Help | Site Map

Report Filter in VBA

John Galt
Guest
 
Posts: n/a
#1: Nov 12 '05
I need to save a report to an RTF and I am using OutputTo acReport:

DoCmd.OutputTo acReport, stDocName, acFormatRTF, TodaysDir & "-" &
"Name.rtf"

This command saves the report nicely, however I cannot filter the report
like I can on an OpenReport and providing a filter statement. Has anyone
found a good way to do this.

I do not want my user to open and preview the report. It must be done
programmatically.

I am using Access 2002.

Please advise.

Thanks in advance





Lyle Fairfield
Guest
 
Posts: n/a
#2: Nov 12 '05

re: Report Filter in VBA


"John Galt" <jsys@yahoo.com> wrote in news:ePBTb.11242$Bv6.3291854
@news1.epix.net:
[color=blue]
> I need to save a report to an RTF and I am using OutputTo acReport:
>
> DoCmd.OutputTo acReport, stDocName, acFormatRTF, TodaysDir & "-" &
> "Name.rtf"
>
> This command saves the report nicely, however I cannot filter the report
> like I can on an OpenReport and providing a filter statement. Has anyone
> found a good way to do this.
>
> I do not want my user to open and preview the report. It must be done
> programmatically.
>
> I am using Access 2002.
>
> Please advise.
>
> Thanks in advance[/color]

One way is to set the RecordSource of your report to a saved query. Before
opening the report, modify the SQL of the query as in:

Const qryChargesName As String = "qryCharges"
Function fCreateAccountFile(strAccountNumber As String)
Dim qdf As QueryDef
Dim rcs As Recordset
Dim strFullPath As String
Set qdf = DBEngine(0)(0).QueryDefs(qryChargesName)
With qdf
.SQL = "SELECT * FROM tblCharges WHERE Sent = No And Account = " &
_
Chr(34) & strAccountNumber & Chr(34)
Set rcs = .OpenRecordset
With rcs
If .RecordCount <> 0 Then
strFullPath = Environ("temp") & _
"\" & "Chargeable Messages for " & strAccountNumber &
".rtf"
DoCmd.OutputTo _
acOutputReport, "rptCharges", acFormatRTF, strFullPath,
False
End If
End With
End With
Set rcs = Nothing
Set qdf = Nothing
End Function

Sub test()
fCreateAccountFile "905 690-2185"
End Sub




--
Lyle
(for e-mail refer to http://ffdba.com/contacts.htm)
John Galt
Guest
 
Posts: n/a
#3: Nov 12 '05

re: Report Filter in VBA


I tried this and I get an error on the dim querydef statement.
It is not a choice in Access 2002 or I am missing something.
I get "User defined type not defined"

????

"Lyle Fairfield" <MissingAddress@Invalid.Com> wrote in message
news:Xns9483CCAA3D067FFDBA@130.133.1.4...[color=blue]
> "John Galt" <jsys@yahoo.com> wrote in news:ePBTb.11242$Bv6.3291854
> @news1.epix.net:
>[color=green]
> > I need to save a report to an RTF and I am using OutputTo acReport:
> >
> > DoCmd.OutputTo acReport, stDocName, acFormatRTF, TodaysDir & "-" &
> > "Name.rtf"
> >
> > This command saves the report nicely, however I cannot filter the report
> > like I can on an OpenReport and providing a filter statement. Has[/color][/color]
anyone[color=blue][color=green]
> > found a good way to do this.
> >
> > I do not want my user to open and preview the report. It must be done
> > programmatically.
> >
> > I am using Access 2002.
> >
> > Please advise.
> >
> > Thanks in advance[/color]
>
> One way is to set the RecordSource of your report to a saved query. Before
> opening the report, modify the SQL of the query as in:
>
> Const qryChargesName As String = "qryCharges"
> Function fCreateAccountFile(strAccountNumber As String)
> Dim qdf As QueryDef
> Dim rcs As Recordset
> Dim strFullPath As String
> Set qdf = DBEngine(0)(0).QueryDefs(qryChargesName)
> With qdf
> .SQL = "SELECT * FROM tblCharges WHERE Sent = No And Account = " &
> _
> Chr(34) & strAccountNumber & Chr(34)
> Set rcs = .OpenRecordset
> With rcs
> If .RecordCount <> 0 Then
> strFullPath = Environ("temp") & _
> "\" & "Chargeable Messages for " & strAccountNumber &
> ".rtf"
> DoCmd.OutputTo _
> acOutputReport, "rptCharges", acFormatRTF, strFullPath,
> False
> End If
> End With
> End With
> Set rcs = Nothing
> Set qdf = Nothing
> End Function
>
> Sub test()
> fCreateAccountFile "905 690-2185"
> End Sub
>
>
>
>
> --
> Lyle
> (for e-mail refer to http://ffdba.com/contacts.htm)[/color]


Lyle Fairfield
Guest
 
Posts: n/a
#4: Nov 12 '05

re: Report Filter in VBA


"John Galt" <jsys@yahoo.com> wrote in
news:W6FTb.11269$Bv6.3295549@news1.epix.net:
[color=blue]
> I tried this and I get an error on the dim querydef statement.
> It is not a choice in Access 2002 or I am missing something.
> I get "User defined type not defined"
>
> ????
>
> "Lyle Fairfield" <MissingAddress@Invalid.Com> wrote in message
> news:Xns9483CCAA3D067FFDBA@130.133.1.4...[color=green]
>> "John Galt" <jsys@yahoo.com> wrote in news:ePBTb.11242$Bv6.3291854
>> @news1.epix.net:
>>[color=darkred]
>> > I need to save a report to an RTF and I am using OutputTo acReport:
>> >
>> > DoCmd.OutputTo acReport, stDocName, acFormatRTF, TodaysDir & "-"
>> > &
>> > "Name.rtf"
>> >
>> > This command saves the report nicely, however I cannot filter the
>> > report like I can on an OpenReport and providing a filter statement.
>> > Has[/color][/color]
> anyone[color=green][color=darkred]
>> > found a good way to do this.
>> >
>> > I do not want my user to open and preview the report. It must be
>> > done programmatically.
>> >
>> > I am using Access 2002.
>> >
>> > Please advise.
>> >
>> > Thanks in advance[/color]
>>
>> One way is to set the RecordSource of your report to a saved query.
>> Before opening the report, modify the SQL of the query as in:
>>
>> Const qryChargesName As String = "qryCharges"
>> Function fCreateAccountFile(strAccountNumber As String)
>> Dim qdf As QueryDef
>> Dim rcs As Recordset
>> Dim strFullPath As String
>> Set qdf = DBEngine(0)(0).QueryDefs(qryChargesName)
>> With qdf
>> .SQL = "SELECT * FROM tblCharges WHERE Sent = No And Account =
>> " &
>> _
>> Chr(34) & strAccountNumber & Chr(34)
>> Set rcs = .OpenRecordset
>> With rcs
>> If .RecordCount <> 0 Then
>> strFullPath = Environ("temp") & _
>> "\" & "Chargeable Messages for " & strAccountNumber &
>> ".rtf"
>> DoCmd.OutputTo _
>> acOutputReport, "rptCharges", acFormatRTF, strFullPath,
>> False
>> End If
>> End With
>> End With
>> Set rcs = Nothing
>> Set qdf = Nothing
>> End Function
>>
>> Sub test()
>> fCreateAccountFile "905 690-2185"
>> End Sub
>>
>>
>>
>>
>> --
>> Lyle
>> (for e-mail refer to http://ffdba.com/contacts.htm)[/color][/color]

Set a reference to dao and qualify the qdf with dao as in
DAO.Qdf

--
Lyle
(for e-mail refer to http://ffdba.com/contacts.htm)
John Galt
Guest
 
Posts: n/a
#5: Nov 12 '05

re: Report Filter in VBA


Thanks.
I did get it working now!


"Lyle Fairfield" <MissingAddress@Invalid.Com> wrote in message
news:Xns9483EE93E844FFDBA@130.133.1.4...[color=blue]
> "John Galt" <jsys@yahoo.com> wrote in
> news:W6FTb.11269$Bv6.3295549@news1.epix.net:
>[color=green]
> > I tried this and I get an error on the dim querydef statement.
> > It is not a choice in Access 2002 or I am missing something.
> > I get "User defined type not defined"
> >
> > ????
> >
> > "Lyle Fairfield" <MissingAddress@Invalid.Com> wrote in message
> > news:Xns9483CCAA3D067FFDBA@130.133.1.4...[color=darkred]
> >> "John Galt" <jsys@yahoo.com> wrote in news:ePBTb.11242$Bv6.3291854
> >> @news1.epix.net:
> >>
> >> > I need to save a report to an RTF and I am using OutputTo acReport:
> >> >
> >> > DoCmd.OutputTo acReport, stDocName, acFormatRTF, TodaysDir & "-"
> >> > &
> >> > "Name.rtf"
> >> >
> >> > This command saves the report nicely, however I cannot filter the
> >> > report like I can on an OpenReport and providing a filter statement.
> >> > Has[/color]
> > anyone[color=darkred]
> >> > found a good way to do this.
> >> >
> >> > I do not want my user to open and preview the report. It must be
> >> > done programmatically.
> >> >
> >> > I am using Access 2002.
> >> >
> >> > Please advise.
> >> >
> >> > Thanks in advance
> >>
> >> One way is to set the RecordSource of your report to a saved query.
> >> Before opening the report, modify the SQL of the query as in:
> >>
> >> Const qryChargesName As String = "qryCharges"
> >> Function fCreateAccountFile(strAccountNumber As String)
> >> Dim qdf As QueryDef
> >> Dim rcs As Recordset
> >> Dim strFullPath As String
> >> Set qdf = DBEngine(0)(0).QueryDefs(qryChargesName)
> >> With qdf
> >> .SQL = "SELECT * FROM tblCharges WHERE Sent = No And Account =
> >> " &
> >> _
> >> Chr(34) & strAccountNumber & Chr(34)
> >> Set rcs = .OpenRecordset
> >> With rcs
> >> If .RecordCount <> 0 Then
> >> strFullPath = Environ("temp") & _
> >> "\" & "Chargeable Messages for " & strAccountNumber &
> >> ".rtf"
> >> DoCmd.OutputTo _
> >> acOutputReport, "rptCharges", acFormatRTF, strFullPath,
> >> False
> >> End If
> >> End With
> >> End With
> >> Set rcs = Nothing
> >> Set qdf = Nothing
> >> End Function
> >>
> >> Sub test()
> >> fCreateAccountFile "905 690-2185"
> >> End Sub
> >>
> >>
> >>
> >>
> >> --
> >> Lyle
> >> (for e-mail refer to http://ffdba.com/contacts.htm)[/color][/color]
>
> Set a reference to dao and qualify the qdf with dao as in
> DAO.Qdf
>
> --
> Lyle
> (for e-mail refer to http://ffdba.com/contacts.htm)[/color]


Closed Thread