Hello all,
I am trying to generate a report from my subform, but I am not having much success in doing so. I am getting either all the records or nothing in my report.
My subform is populated from an unbound listbox; here is the code that is used to populate the subform:
And this is what I am trying to open my report with:
With "LightDuty" being my report.
Any help would be appreciated.
I am trying to generate a report from my subform, but I am not having much success in doing so. I am getting either all the records or nothing in my report.
My subform is populated from an unbound listbox; here is the code that is used to populate the subform:
Code:
'Populates the subform from the second listbox
Dim strQueryFieldSelected As String
Dim strQueryValueSelected As String
Dim db As DAO.Database
On Error GoTo ErrorHappened
If lstQValues.ListIndex <> -1 And lstQFields.ListIndex <> -1 Then
strQueryFieldSelected = lstQFields.ItemData(lstQFields.ListIndex)
strQueryValueSelected = lstQValues.ItemData(lstQValues.ListIndex)
Set db = CurrentDb
'Me.txtCounter = DCount("strqueryfieldselected", "PSU")
If CurrentDb.TableDefs("LightDuty").Fields(strQueryFieldSelected).Type = dbDate Then
strSQL = "SELECT [" & strQueryFieldSelected & "], * FROM LightDuty WHERE [" & strQueryFieldSelected & "] = #" & strQueryValueSelected & "# ORDER BY #" & strQueryValueSelected & "# ASC"
Else
strSQL = "SELECT [" & strQueryFieldSelected & "], * FROM LightDuty WHERE [" & strQueryFieldSelected & "] = """ & strQueryValueSelected & """ ORDER BY """ & strQueryValueSelected & """ ASC"
End If
Debug.Print strSQL
Set subQResults.Form.Recordset = db.OpenRecordset(strSQL, dbOpenSnapshot)
Else
GoTo ExitNow
End If
ExitNow:
On Error Resume Next
Set db = Nothing
Exit Sub
ErrorHappened:
MsgBox "Error " & Err.Number & " (" & Err.Description & ")"
Resume ExitNow
Resume
And this is what I am trying to open my report with:
Code:
DoCmd.OpenReport "LightDuty", acViewPreview, , acDialog
With "LightDuty" being my report.
Any help would be appreciated.