How to grab the value of a radio button in VBA (1 Viewer)

Lkwdmntr

Registered User.
Local time
Yesterday, 16:01
Joined
Jul 10, 2019
Messages
281
Hi guys,

I have three radio buttons (Screen, Print, PDF) that I am using to view, print, and save my reports. I am using nested if statements that look like this.

Code:
If Me.txtReportName = "Week at a Glance" Then
    If Me.rdbScreen.Value = True Then
        DoCmd.OpenReport "rptWeekAtAGlance", acViewPreview
    End If
        If Me.rdpPrinter.Value = True Then
            DoCmd.OpenReport "rptWeekAtAGlance", acNormal
            End If
End If

I haven't figured out how to save to PDF yet, but I'm getting an error "You've entered an expression that has no value"

Any ideas on how I can remedy this problem?
 
Last edited:

Gasman

Enthusiastic Amateur
Local time
Today, 00:01
Joined
Sep 21, 2011
Messages
14,317
Use the wizard to create an option group.
 

Lkwdmntr

Registered User.
Local time
Yesterday, 16:01
Joined
Jul 10, 2019
Messages
281
Ok, I got it. I already had them as a group, I didn't realize they had a value of 1, 2, 3. Thanks! Now I need to figure out how to save the report as a pdf to my computer.
 

Gasman

Enthusiastic Amateur
Local time
Today, 00:01
Joined
Sep 21, 2011
Messages
14,317
Been asked many times here.
Do a search here, or even a Google. No point guessing.
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 19:01
Joined
Feb 19, 2002
Messages
43,302
Here's a sample from one of my apps. It uses an option group with a select case.

Case 3 is the export to PDF. The problem with exporting to PDF arises because the OutputTo method does NOT include a where argument the way the OpenReport method does. THEREFORE, you will see two different solutions. One solution opens the report in print preview and then runs the OutputTo. This is OK if you only ever have to print ONE report but if you have to print multiples, it is very inefficient and slow. So, I use a different method. In this case, the report is bound to a query that has a where clause that references form fields. The picture shows the criteria fields. As you click on each report, different fields are unhidden in the Criteria section and the Where clause uses those.

This is the query for the selected report:

Code:
SELECT [tblEmployees]![LastName] & (", "+[tblEmployees]![FirstName]) AS CareMgr, tblClients.ClientID, tblClients.ems, [tblClients]![LastName] & IIf(IsNull([tblClients]![FirstName]),"",", " & [tblClients]![FirstName]) AS ClientName, tblClientStatus.StatusDT, tblClientStatus.StatusID, tblStatusCodes.ShortName AS Status, tblSubStatus.ShortName AS SubStatus

FROM tblEmployees RIGHT JOIN (((tblClients LEFT JOIN qMaxStatus ON tblClients.ClientID = qMaxStatus.ClientID) LEFT JOIN (tblStatusCodes RIGHT JOIN tblClientStatus ON tblStatusCodes.StatusID = tblClientStatus.StatusID) ON (qMaxStatus.ClientID = tblClientStatus.ClientID) AND (qMaxStatus.StatusChangeID = tblClientStatus.StatusChangeID)) LEFT JOIN tblSubStatus ON tblClientStatus.SubStatusID = tblSubStatus.SubStatusID) ON tblEmployees.EmpID = tblClients.CareMgrID

WHERE (IIf([forms]![frmVariables]![fraStatus]=2,IIf([tblClients]![StatusID]=1319,True,False),IIf([forms]![frmVariables]![fraStatus]=1,IIf([tblClients]![StatusID]=1318,True,False),IIf([forms]![frmVariables]![fraStatus]=4,IIf([tblClients]![StatusID]=1427,True,False),True)))=True)
And  (tblClients.CareMgrID = [forms]![frmVariables]![cboCM] OR [forms]![frmVariables]![cboCM] Is Null)

And  (tblStatusCodes.StatusID = [forms]![frmVariables]![cboCarePlanStatus] OR [forms]![frmVariables]![cboCarePlanStatus] Is Null)


And tblClientStatus.StatusDT <= [Forms]![frmReports]![txtThruDT] or [Forms]![frmReports]![txtThruDT] is null;
AOAPrintReports.JPG


The code has been altered to remove most of what is irrelevant so I hope I didn't miss anything important.
Code:
Private Sub cmdRun()
    Dim strReport As Variant
    Dim strWHERE As Variant
    Dim strFileName As String
   
    On Error GoTo cmdRun_Click_Error
    Select Case Me.fraOutputTo
        Case 1      'Preview
            DoCmd.OpenReport strReport, acViewPreview
        Case 2      'Print
            DoCmd.OpenReport strReport, acViewNormal
        Case 3      'Export to PDF
            If Me.txtPath & "" = "" Then
                MsgBox "Please select a path.", vbOKOnly
                Me.cmdBrowse.SetFocus
                Exit Sub
            End If
            strFileName = Me.txtPath & "\" & strReport & "_" & Format(Date, "yyyymmdd") & ".pdf"
            DoCmd.OutputTo acOutputReport, strReport, acFormatPDF, strFileName
        Case 4      'Export to Excel
            If Me.txtPath & "" = "" Then
                MsgBox "Please select a path.", vbOKOnly
                Me.cmdBrowse.SetFocus
                Exit Sub
            End If
            strFileName = Me.txtPath & "\" & Me.txtExcelQueryName & "_" & Format(Date, "yyyymmdd") & ".xlsx"
            Kill strFileName
            If Me.lstReports.Column(3) = "P-01" Then        'Weekly Job Status
                DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, Me.txtExcelQueryName, strFileName, False
            Else
                DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, Me.txtExcelQueryName, strFileName, True
            End If
            MsgBox "Export Complete - File name = " & strFileName
    End Select
cmdRun_Click_Exit:
    Exit Sub

cmdRun_Click_Error:
    Select Case Err.Number
        Case 53 'file not found for kill
            Resume Next
        Case 2501
            Resume cmdRun_Click_Exit
        Case Else
            MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure cmdRun_Click of VBA Document Form_frmReports"
    End Select
    Resume cmdRun_Click_Exit
    Resume Next
End Sub
 
Last edited:

Users who are viewing this thread

Top Bottom