This makes since now that pointed this out. My original adopted code had this:
Code:
Private Sub cmdExport_Click()
On Error GoTo Err_cmdExport_Click
Dim strSQL As String, intCounter As Integer
Dim ctl As Control, strname As String, strnewquery As String
Dim strRptSel As String
Dim stMessage As String
Set db = CurrentDb
'Build SQL String
For Each ctl In Me.Form
If ctl.Tag = "input" Then
'strname = "me." & ctl.Name
If ctl.Value > "" Then
strSQL = strSQL & "[" & ctl.Name & "] " & " like " & Chr(34) & ctl.Value & Chr(34) & " And "
End If
End If
Next ctl
' Set the value of the parameter.
Select Case Me.Module
Case SP
strnewquery = "[qrySPReports_test_passthru]"
Case LTL
strnewquery = "[qryLTLReports_test_passthru]"
Case DTF
strnewquery = "[qryDTFReports_test_passthru]"
End Select
If Me.cboFROM & vbNullString <> "" And Me.cboTO & vbNullString <> "" Then
strSQL = strSQL & " ([MONTHPROCESSED] BETWEEN " & Me.cboFROM & " And " & Me.cboTO & ") And "
End If
'strnewquery = "Select [qrySPReports_test_passthru].* FROM [qrySPReports_test_passthru]"
If strSQL <> "" Then
strSQL = Left(strSQL, (Len(strSQL) - 5))
strnewquery = strnewquery & " WHERE " & strSQL & ";"
End If
Debug.Print strnewquery
' Create the recordset
Set rs = db.OpenRecordset(strnewquery)
If rs.RecordCount > 0 Then
DoCmd.OpenQuery strnewquery, acViewNormal, strSQL
DoCmd.Close acForm, "frmREPORTBUILDER"
Else
MsgBox "There are no records that match your criteria! Please select new criteria.", vbInformation
Exit Sub
End If
DoCmd.Minimize
stDocName = strnewquery
DoCmd.OpenQuery strnewquery, acViewNormal, strSQL
DoCmd.Close acForm, "frmREPORTBUILDER"
stDocName = strnewquery
DoCmd.OpenQuery stDocName, acPreview
DoCmd.OutputTo acOutputQuery, strnewquery, acFormatXLS
DoCmd.Close strnewquery
Exit_cmdExport_Click:
Exit Sub
Err_cmdExport_Click:
Select Case Err.Number
Case 2501 'OpenQuery action was cancelled
Resume Exit_cmdExport_Click
Case Else
MsgBox Err.Description
Resume Exit_cmdExport_Click
Resume
End Select
End Sub
I have to scratch this from the beginning because I need to have something in place now so the users can use it. Im open for suggestions.
Thank you for your patience.