Groundrush
Registered User.
- Local time
- Today, 13:06
- Joined
- Apr 14, 2002
- Messages
- 1,376
Using various combo boxes I have a system that limits & displays records depending on what has been selected. it works well using the code below but I need to be able to also output the results to an excel spreadsheet or maybe be able to print print.
can someone please assist me & see if this code can be altered to allow this as I can't seem to work it out.
Thanks
can someone please assist me & see if this code can be altered to allow this as I can't seem to work it out.
Code:
Private Sub cmdSearch_Click()
'Set the Dimensions of the Module
Dim strsql As String, strOrder As String, strWhere As String
Dim dbNm As Database
Dim qryDef As QueryDef
Set dbNm = CurrentDb()
'Constant Select statement for the RowSource
strsql = "SELECT qryTaskControl.TaskID,qryTaskControl.EformRef,qryTaskControl.Contract,qryTaskControl.JobNo, qryTaskControl.DateReported,qryTaskControl.DueBy,qryTaskControl.ContractName,qryTaskControl.Priority, qryTaskControl.PropertyName, qryTaskControl.PropertyAddress,qryTaskControl.Location,qryTaskControl.JobDetails,qryTaskControl.FurtherDetails,qryTaskControl.Category,qryTaskControl.Trade,qryTaskControl.CallersName,qryTaskControl.CallersPhoneNumber,qryTaskControl.EstimatedCost,qryTaskControl.LOC,qryTaskControl.Status,qryTaskControl.Cancelled,qryTaskControl.History, qryTaskControl.Printed " & _
"FROM qryTaskControl"
strWhere = "WHERE"
'strOrder = "ORDER BY qryTaskControl.DateReported;" ' do not remove the comment as it will reverse the order of the records
'Set the WHERE clause for the Listbox RowSource if information has been entered into a field on the form
If Not IsNull(Me.txtEformRef) Then
strWhere = strWhere & " (qryTaskControl.EformRef) Like '*" & Me.txtEformRef & "*' AND"
End If
If Not IsNull(Me.cboContract) Then '<--If the textbox cboContract No contains no data THEN do nothing
strWhere = strWhere & " (qryTaskControl.Contract) Like '*" & Me.cboContract & "*' AND"
End If
If Not IsNull(Me.cboJobNo) Then
strWhere = strWhere & " (qryTaskControl.JobNo) Like '*" & Me.cboJobNo & "*' AND"
End If
If Not IsNull(Me.txtDateReported) Then
strWhere = strWhere & " (qryTaskControl.DateReported) Like '*" & Me.txtDateReported & "*' AND"
End If
If Not IsNull(Me.cboPriority) Then
strWhere = strWhere & " (qryTaskControl.Priority) Like '*" & Me.cboPriority & "*' AND"
End If
If Not IsNull(Me.cboProperty) Then
strWhere = strWhere & " (qryTaskControl.PropertyName) Like '*" & Me.cboProperty & "*' AND"
End If
If Not IsNull(Me.txtJobDetails) Then
strWhere = strWhere & " (qryTaskControl.JobDetails) Like '*" & Me.txtJobDetails & "*' AND"
End If
If Not IsNull(Me.cboTrade) Then
strWhere = strWhere & " (qryTaskControl.Trade) Like '*" & Me.cboTrade & "*' AND"
End If
If Not IsNull(Me.cboCallersName) Then
strWhere = strWhere & " (qryTaskControl.CallersName) Like '*" & cboCallersName & "*' AND"
End If
If Not IsNull(Me.cboLOC) Then
strWhere = strWhere & " (qryTaskControl.LOC) Like '*" & Me.cboLOC & "*' AND"
End If
If Not IsNull(Me.cboStatus) Then
strWhere = strWhere & " (qryTaskControl.Status) Like '*" & Me.cboStatus & "*' AND"
End If
'Remove the last AND from the SQL statment
strWhere = Mid(strWhere, 1, Len(strWhere) - 5)
'Pass the SQL to the RowSource of the listbox
Me.lstTasks.RowSource = strsql & " " & strWhere & "" & strOrder
End Sub
Thanks
