Can you use a SQL for the report name when using the DoCmd.openreport

lws

Registered User.
Local time
Today, 12:27
Joined
Mar 14, 2013
Messages
22
I have several different reports that I would like to open from a single form depending upon what the user selects. Is there a way to use a SQL for the name of the report in the DoCmd.openreport command? Or do I have to use a cascading string of If statements?

I have code that places either Daily, Monthly, or Quarterly in the following field.

[Forms]![F_View_Logs]![VerTag]

Can I use a SQL or a veariable to interchange Daily in the code below?

DoCmd.OutputTo acReport, "R_Daily_Logs", "", , , "", 0, acExportQualityPrint
 
Code:
Dim strType As string
 
strType = "R_" & Forms!F_View_Logs.VerTag & "_Logs"
 
DoCmd.OutputTo acReport, [B][COLOR=red]strType[/COLOR][/B], , , , , 0, acExportQualityPrint

And, by the way, you don't put "" in parameters there. Just leave them blank if you aren't using them. If you are and you just left them so the paths weren't shown, then ignore my statement.
 
When I use that code I get an error.

Run time error 2465
Application-defined or object-defined error
 
Get rid of the 0 as it is in the Encoding Parameter and that is not a valid option. Also, can you post the exact code you are using? Don't remove anything so we can see what other things might be conflicting.
 
Sorry for the delayed response. I was called away to another project.
I was able to get it to work. I found a type-o in my code. Thanks for your assistance. I appreciate it.
Below is the full code for FYI.

Code:
Private Sub Cancel_Click()
 
DoCmd.Close
End Sub
 
 
 
Private Sub Form_Load()
 
Me.Caption = "View " & [Forms]![F_View_Logs_Menu]![verTag] & " Logs"
End Sub
 
 
 
Private Sub List_Date_DblClick(Cancel As Integer)
 
Dim Msg, Style, Help, Ctxt, Response, MyString
Dim strSQL As String
On Error GoTo Err_List_Date_DblClick
 
[Forms]![F_View_Logs]![VerDate] = Me.List_Date
 
strSQL = "R_" & [Forms]![F_View_Logs_Menu]![verTag] & "_Log"
 
 
'********************************************************************************************************************************
'*
'*             SAVE REPORT TO FILE? OR JUST VIEW
'*
'********************************************************************************************************************************
 
    MyValue = "Do You Want To Save As A File?"
    Msg = MyValue    ' Define message.
    Style = vbYesNo + vbCritical + vbDefaultButton2    ' Define buttons.
    Title = "Save As A File?"    ' Define title.
    Help = "DEMO.HLP"    ' Define Help file.
    Ctxt = 1000    ' Define topic
 
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
 
If Response = vbYes Then
 
    DoCmd.OutputTo acReport, strSQL, "", , , "", acExportQualityPrint
    DoCmd.Close acForm, "F_View_Logs"
 
    Else:
 
    DoCmd.OpenReport strSQL, acViewReport
    DoCmd.Close acForm, "F_View_Logs"
 
End If
Exit_List_Date_DblClick:
    Exit Sub
 
Err_List_Date_DblClick:
    Err.Description = "Action Canceled"
    MsgBox Err.Description
    Resume Exit_List_Date_DblClick
 
End Sub
 
 
 
Private Sub Unit_Change()
 
DoCmd.RefreshRecord
End Sub


Thanks again
 
Last edited:

Users who are viewing this thread

Back
Top Bottom