topdesk123
Registered User.
- Local time
- Today, 14:17
- Joined
- Mar 28, 2013
- Messages
- 53
Hi!
I'm trying to run a report that is filtered by a form that contains several text fields and multi-select list boxes. I am working on one section right now and I'm getting a syntax error. If I run the sql by itself, I get correct data. Here's the code:
I'm trying to run a report that is filtered by a form that contains several text fields and multi-select list boxes. I am working on one section right now and I'm getting a syntax error. If I run the sql by itself, I get correct data. Here's the code:
Code:
Variant
Dim sSql As String
Set ctlList = [Forms]![FReportParams]!Salespeople
Set ctlList2 = [Forms]![FReportParams]!ProdGrp
Set ctlList3 = [Forms]![FReportParams]!MFGS
Set ctlList4 = [Forms]![FReportParams]!Bidders
Set ctlList5 = [Forms]![FReportParams]!status
'Purpose: Build up the criteria string form the non-blank search boxes, and apply to the form's Filter.
'Notes: 1. We tack " AND " on the end of each condition so you can easily add more search boxes; _
we remove the trailing " AND " at the end.
' 2. The date range works like this: _
Both dates = only dates between (both inclusive. _
Start date only = all dates from this one onwards; _
End date only = all dates up to (and including this one).
Dim strwhere As String 'The criteria string.
Dim lngLen As Long 'Length of the criteria string to append to.
Const conJetDate = "\#mm\/dd\/yyyy\#" 'The format expected for dates in a JET query string.
' 'Date field example. Use the format string to add the # delimiters and get the right international format.
If Not IsNull([Forms]![FReportParams]![BidStartDate_BeginR]) Then
strwhere = strwhere & "([biddate] >= " & Format([Forms]![FReportParams]![BidStartDate_BeginR], conJetDate) & ") AND "
' Debug.Print bidate & " " & BidStartDate_BeginR
End If
If Not IsNull([Forms]![FReportParams]![BidstartDate_EndR]) Then
strwhere = strwhere & "([biddate] <= " & Format([Forms]![FReportParams]![BidstartDate_EndR]) & ") AND "
' Debug.Print bidate & " " & BidstartDate_EndR
End If
'sSql = "SELECT ProjectItems.TOPersonID, ProjectItems.Person, Persons.PersonID, Projects.FollowUpDate, Projects.QuoteCompleted, Projects.ProjectNo, Projects.ProjectName, Projects.BidDate, ProjectNotes.Note, Projects.ProjectID, ProductGrps.ProductGroup, ProjectItems.ItemBid " & vbCrLf & _
'"FROM Persons INNER JOIN (((Projects INNER JOIN ProjectItems ON Projects.ProjectID = ProjectItems.ProjectID) LEFT JOIN ProjectNotes ON Projects.ProjectID = ProjectNotes.ProjectID) INNER JOIN ProductGrps ON ProjectItems.ProductGrpID = ProductGrps.ProductGrpID) ON Persons.PersonID = ProjectItems.TOPersonID " & vbCrLf & _
'"WHERE (((ProjectItems.TOPersonID) In (28,8)));"
sSql = "SELECT * FROM masterquery WHERE topersonid IN ("
For Each Lmnt In ctlList.itemsselected
sSql = sSql & ctlList.ItemData(Lmnt) & ","
Next
sSql = Left(sSql, Len(sSql) - 1) & ")" 'Remove Last comma and single quote and add closing bracket
Debug.print gives me:
?ssql
SELECT * FROM masterquery WHERE topersonid IN (8,28)
If I use IN(8,28) in the query it works. Please help me, what am I missing? Thank you in advance!!
DoCmd.Openreport Forms![FMainMenu]![FReports].Form![ReportName].Column(3), acViewPreview, , sSql
DoCmd.SetWarnings False
Forms("freportparams").SetFocus
DoCmd.Minimize
DoCmd.SetWarnings True
End Sub