Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DoCmd.OutputTo - Word Problem with Where Clause 2

Status
Not open for further replies.

DomFino

IS-IT--Management
Jul 9, 2003
278
US
I have a view report button on a form. Currently, when clicked the report opens in Access preview for the current record via the where clause.

What I need is to have the report open in Word RTF format.

I looked in Help and found the DoCmd.OutputTo write up but it does not seem to have enough variables to allow for the WHERE portion of the code. Does anyone know how to code the DoCmdOutputTo with a where clause?

Code:
'***************Begin Code **************************

Private Sub Vital_Stats_View_Click()
On Error GoTo Err_Vital_Stats_View_Click

Dim stDocName As String
stDocName = "SelectLabelsVitalStats"

' ***************This line works now ************** 
DoCmd.OpenReport stDocName, acPreview, , "ID = " & Forms!MasterForm!ID

[COLOR=red]
[b]
'******This is the line I would like to use ************** 
'DoCmd.OutputTo acOutputReport, stDocName, acFormatRTF, "ID = " & Forms!MasterForm!ID
[/color]
bold[/b]

Exit_Vital_Stats_View_Click:
Exit Sub

Err_Vital_Stats_View_Click:
MsgBox Err.Description
Resume Exit_Vital_Stats_View_Click

End Sub

'***************End Code **************************
 
Try this:

DoCmd.OutputTo acOutputReport, stDocName, acFormatRTF, "ID = '" & Forms!MasterForm!ID & "'"

If the Master Form ID is String, you need the single quotes.


Jim DeGeorge [wavey]
 
Hi jdegeorge,
Thanks for the reply. Unfortunately, it did not work. When I select the button a box appears scrolling through all the records in the database and not opening Word as apposed to going directly to the singlle ID and then opening Word. I tried it with and without the single quotes. The WHERE clause is not being run for some reason.
Any other suggestions?
 
I use where for previewing reports and I always name the form that the WHERE field is from. For example, instead of just "ID", I put "Me.ID".

Jim DeGeorge [wavey]
 
Jim,
Tried it. Didn't make any difference. The code simply does not seem to execute the WHERE.
Dom
 
Access help shows this as the syntax:

DoCmd.OutputTo acOutputTable, "Employees", acFormatRTF, "Employee.rtf", True

DoCmd.OutputTo acOutputReport, stDocName, acFormatRTF, "OUTPUT.RTF", "ID = " & Forms!MasterForm!ID

First, you didn't name the output file before your WHERE filter.

Should be where I've indicated RED.

Second, the last syntax is something called ENCODING. Doesn't say that this is a filter, as in the case with the openreport syntax. But, if it is, by adding the name of the file, or at least adding the missing comma, this should do it.

Jim DeGeorge [wavey]
 
Jim,
I too went back and re-read the Help. Your comments were, of course all valid. I did have to put the output file in a string with full path per the help instructions. Anyway, I now have something working but it still does not do the where protion of the code.

Here is what I have now:
Code:
Private Sub Vital_Stats_View_Click()
On Error GoTo Err_Vital_Stats_View_Click

    Dim stDocName As String
    Dim stOutput As String
    
    stDocName = "SelectLabelsVitalStats"
    stOutput = "C:\My Documents\Output.RTF"
    
    DoCmd.OutputTo acOutputReport, [stDocName], [acFormatRTF], [stOutput], True, "ID = " & Forms!MasterForm!ID

More code . . .
What happens is the entire contents of the report is sent to the output file not just the ID on the open form. I have tried this many ways and still no luck. I took out the ",TRUE" I put the ",TRUE" at the end, etc.

Still stumped.
 
Dom

I've never used OutputTo before, but the syntax stops at TRUE/FALSE. You seem to be assuming that you can assign a WHERE clause to this in the syntax but I can't see where or how.

You may need to do this elsewhere, possibly in the query that controls the report.

Jim DeGeorge [wavey]
 
Jim,
You are right. I guess I figured that since I could do a where in other DoCmd functions that I could do one here as well. No such luck.
Thank you for all your time and suggestions. I did learn something form the process so that's a good thing.
Dom
 
Dom

Sorry you can't do what you want to do, but glad that you learned somethign new.[smarty]

Keep pluggin' away!

Jim DeGeorge [wavey]
 
try

DoCmd.OpenReport stDocName, acPreview, , "ID = " & Forms!MasterForm!ID
DoCmd.OutputTo acOutputReport, stDocName, acFormatRTF
the first docmd creates the report the second docmd will output the report in rtf format in My Documents folder

I think

Hope this helps
Hymn
 
Hi Hymn,
Nice try. I thought your suggestion was rather interesting but it did not work. Access pops up with the file folder save box, which contains the directory in which my Access Data base is running along with the appropriate file name. I press OK, and Access comes back with “File already exists do you want save anyway”. I say OK, and Access simply goes back to the preview screen and stores a copy in the file folder where the Access Database resides.

HOWEVER, it did get me to thinking along your path. I played around and finally got it. Here is the code that now WORKS!!!

Thanks to you and Jim, this puppy can get some rest! Well done guys!! Have a STAR on me!!!
Dom
Code:
Private Sub Vital_Stats_View_Click()
On Error GoTo Err_Vital_Stats_View_Click

    Dim stDocName As String
    Dim stOutput As String
    
    stDocName = "SelectLabelsVitalStats"
    stOutput = "C:\My Documents\Output.RTF"
      
    DoCmd.OpenReport stDocName, acPreview, , "ID = " & Forms!MasterForm!ID
    DoCmd.OutputTo acOutputReport, stDocName, acFormatRTF, stOutput, True

Exit_Vital_Stats_View_Click:
    Exit Sub

Err_Vital_Stats_View_Click:
    MsgBox Err.Description
    Resume Exit_Vital_Stats_View_Click
    
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top