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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Output a report in rtf with a field as the file name?? 1

Status
Not open for further replies.

Triacona

Technical User
Jun 11, 2009
462
GB
Hi,
Any help would be really appreciated. [smile]

The problem is this:
I can output to an rtf file and give it a static name;
The user clicks on the combo box (combo0) and chooses a reference value which is generated with the field: REFVAL from the Query (AllDetailsCard)

The Query (ChsRef) (with the field REFVAL, which has the criteria [Forms]![ChsRef].[Combo0]) then takes the input and generates the Report (HcnyCrgDri)
- which does not display but is used to create the rtf file.

As the code on my Form (ChsRef) cmd button below demonstrates I can output to a statically named rtf file:

Code:
Private Sub HnkyCrDriCrd_Click()
On Error GoTo Err_HnkyCrDriCrd_Click

    Dim stDocName As String

    stDocName = "HcnyCrgDri"
    
        DoCmd.OutputTo acOutputReport, stDocName, acFormatRTF, "Hackney Carriage License.rtf"
       
    
    
Exit_HnkyCrDriCrd_Click:
    Exit Sub

Err_HnkyCrDriCrd_Click:
    MsgBox Err.Description
    Resume Exit_HnkyCrDriCrd_Click
    
End Sub
What I want to do is use the Field: REFVAL in the Query: ChsRef to name the file when it is generated;
So it will have field REFVAL.rtf as the filename therefore not a static filename.

I have tried the following code:
Code:
Private Sub HnkyCrDriCrd_Click()
On Error GoTo Err_HnkyCrDriCrd_Click

    Dim stDocName As String

    stDocName = "HcnyCrgDri"
    
    DoCmd.OutputTo acOutputReport, stDocName, acFormatRTF, [COLOR=red yellow][Forms]![ChsRef].[Combo0][/color]
    
    
    
Exit_HnkyCrDriCrd_Click:
    Exit Sub

Err_HnkyCrDriCrd_Click:
    MsgBox Err.Description
    Resume Exit_HnkyCrDriCrd_Click
    
End Sub
BUT I get this error:
Microsoft Office Access can't save the data to the file you've selected
If I put:
Code:
Private Sub HnkyCrDriCrd_Click()
On Error GoTo Err_HnkyCrDriCrd_Click

    Dim stDocName As String

    stDocName = "HcnyCrgDri"
    
    DoCmd.OutputTo acOutputReport, stDocName, acFormatRTF, [Forms]![ChsRef].[Combo0][COLOR=red yellow].rtf[/color]
    
    
    
Exit_HnkyCrDriCrd_Click:
    Exit Sub

Err_HnkyCrDriCrd_Click:
    MsgBox Err.Description
    Resume Exit_HnkyCrDriCrd_Click
    
End Sub
Object doesn't support this property or method

If I add
Code:
DoCmd.OutputTo acOutputReport, stDocName, acFormatRTF, "[Forms]![ChsRef].[Combo0].rtf"
It just names it with the exact above string.

I'm banging my head on this one;[banghead]
Your help would really be great! [smile]
Thank you [bigsmile]
Kind regards
Triacona
 
How about:
Code:
DoCmd.OutputTo acOutputReport, stDocName, acFormatRTF, [Forms]![ChsRef].[Combo0] & ".rtf"
Hope this helps

HarleyQuinn
---------------------------------
Carter, hand me my thinking grenades!

You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before post
 
Thank you very, very much [smile][2thumbsup]
It works, well only with a different field, because the field has slashes in it (009/009/TXHCD)
but the field I choose PLATEREF has a standard string (H09)

Is there a way of binding to combo boxes together in the same Form (ChsPlate) ?

I want to use the FIELD PLATEREF to link to the FIELD REFVAL and display in the REFVAL combo box all the instances of REFVAL that occur for PLATEREF.

The Query (ChsPlate) has 2 criteria [Forms]![ChsPlate].[combo1] in the REFVAL FIELD Criteria; and

[Forms]![ChsPlate].[combo0] in the PLATEREF FIELD Criteria

Would it be possible to use the FIELD PLATEREF to link to the FIELD REFVAL and display in the REFVAL [COLOR=red yellow]Combo Box[/color] all the instances of REFVAL that occur for PLATEREF.

Thank you again for your help [bigsmile]
Kind regards
Triacona
 
Hi Harley,

I managed to solve the last part of my problem:
I have 2 queries, one with no criteria and the other(PlateChs)with the criteria:
Code:
[Forms]![ChsPltRef].[combo0]
The NFrmCRefAs query has no form criteria and therefore is the query I use to generate the PLATEREF field list combo0 in the ChsPltRef Form.

The Reference numbers(REFVAL) are generated with the query PlateChs.

So if the user chooses the PLATEREF from the combo0 then the combo1 (REFVAL) displays the reference numbers related to that Plate number (PLATEREF)

Kind regards
Triacona
 
Sorry I didn't get back to you before you sorted it yourself, glad you got it fixed though! [smile]

HarleyQuinn
---------------------------------
Carter, hand me my thinking grenades!

You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before post
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top