Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RunTime Error: 3360

Status
Not open for further replies.

yummy7

Technical User
Jun 2, 2006
195
CA
Hi All,
I have stuck in great trouble.
When I click on command button to view Query which selects StoreNo from List.It works fine if some stores selected.But when I select round about 300 stores from list,it gives runtime error:3360 'query is too complex '.Following is code.
Private Sub Command18_Click()
CurrentDb.QueryDefs("Report").SQL = "SELECT Snumber,System_Type from Store_t where " & GetCriteria()
DoCmd.OpenQuery "Report", acViewPreview
End Sub

<-Function to get Store Nos from List->
Private Function GetCriteria() As String
Dim stDocCriteria As String
Dim varItm As Variant

For Each varItm In Forms![rptStores]!List10.ItemsSelected
stDocCriteria = stDocCriteria & "[Snumber] = " & Forms![rptStores]!List10.Column(0, varItm) & " OR "
Next
If stDocCriteria <> "" Then
stDocCriteria = Left(stDocCriteria, Len(stDocCriteria) - 4)
Else
stDocCriteria = "True"
End If

GetCriteria = stDocCriteria
End Function
Kindly help me.
 
You may try this function instead:
Private Function GetCriteria() As String
Dim stDocCriteria As String
Dim varItm As Variant
With Forms![rptStores]!List10
For Each varItm In .ItemsSelected
stDocCriteria = stDocCriteria & "," & .Column(0, varItm)
Next
End With
If stDocCriteria <> "" Then
stDocCriteria = "Snumber In (" & Mid(stDocCriteria, 2) & ")"
Else
stDocCriteria = "1=1"
End If
GetCriteria = stDocCriteria
End Function

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
It may be quicker and easier to add records to a temporary table, which could then be used in a query to select a set of records.
 
Thanx alot PHV.It works. Also thanx Remou for your positive Response.
 
Tell me its function PHV
stDocCriteria = "1=1" ?

You bring happiness to many faces,you are really great.
 
It's an expression that always evaluate to true.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top