Hi all,
I have seen forms in databases where users select from unbound fields and click a button that would give them a report based on their selections. Here's is the code but it give me an error "object required"
I have seen forms in databases where users select from unbound fields and click a button that would give them a report based on their selections. Here's is the code but it give me an error "object required"
Private Sub cmdPreview_Click()
On Error GoTo Err_cmdPreview_Click
On Error GoTo Err_cmdPreview_Click
Dim strSQL As String
Dim strnewQuery As String
Dim strnewQuery As String
strSQL = strSQL & "[" & ctl.Name & "] " & " like " & Chr(34) & ctl.Value & Chr(34) & " And "
strnewQuery = "SELECT qryOccurences_All.*, qryOccurences_All. FROM qryOccurences_All.IDX_OccurID WHERE " & strSQL & ";"
Dim rptDocName As String
rptDocName = "rptOccur_All"
DoCmd.OpenReport rptDocName, acPreview
If strSQL <> "" Then
MsgBox "There are no records that match your criteria! Please select new criteria.", vbInformation
Exit Sub
Else
DoCmd.OpenReport "rptOccur_All", acViewPreview
DoCmd.Close acForm, "frmReportbuiler"
Exit Sub
DoCmd.OpenReport rptDocName, acPreview
If strSQL <> "" Then
MsgBox "There are no records that match your criteria! Please select new criteria.", vbInformation
Exit Sub
Else
DoCmd.OpenReport "rptOccur_All", acViewPreview
DoCmd.Close acForm, "frmReportbuiler"
Exit Sub
Exit_cmdPreview_Click:
Exit Sub
Exit Sub
Err_cmdPreview_Click:
MsgBox Err.Description
Resume Exit_cmdPreview_Click
Resume
End If
End Sub
MsgBox Err.Description
Resume Exit_cmdPreview_Click
Resume
End If
End Sub
Please help me with my code.
Thanks

reportbuilder
V&#237;ctor M.
CarlBrochu
Hi,
If that line is giving you an object required error then I'd check if the ctl variable has been defined. Your code snippet doesn't define it. Thats the only thing on that line that would cause that error.
Also this line...
If strSQL <> "" Then
will always be true because you always set strSQL's value with the line thats causing the error. You'll want to check a RecordCount here.
Josamoto80
also.... sorry...
it looks like your code has been set up to run in a loop, but your not calling it in a loop. So you can remove the inital strSQL from the start of this line.
strnewQuery = "SELECT qryOccurences_All.*, qryOccurences_All. FROM qryOccurences_All.IDX_OccurID WHERE " & strSQL & ";"
Victor Lobanov
Hi,
What line of code gives you the error