473,513 Members | 2,339 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Combine selections from listbox in VBA

22 New Member
Hi - I've adopted some code from font stuff to be able to select multiple rows in a list box to send to a query.

I'm using an Autonumber ID field to identify the records I want from the list.

Can anyone help me with my run-error 3075 on STMT2? Syntax Error(missing operator) in query expression '[qdfMULTI.CustID] in (100',102')'.
Those are the correct items, but when I check my query, it is returning all.


Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdMULTI_Click()
  2.     Dim ms As DAO.Database
  3.     Dim STMT2 As DAO.QueryDef
  4.     Dim varitem As Variant
  5.     Dim strCriteria As String
  6.     Dim strSQL As String
  7.  
  8.     Set ms = CurrentDb()
  9.     Set STMT2 = ms.QueryDefs("qrySTMTMM")
  10.  
  11.     For Each varitem In Me!lstMM.ItemsSelected
  12.         strCriteria = strCriteria & "," & Me!lstMM.ItemData(varitem) & "'"
  13.     Next varitem
  14.  
  15.     If Len(strCriteria) = 0 Then
  16.         MsgBox "You did not select anything from the list!", vbExclamation, "Nothing to Find!"
  17.     Exit Sub
  18.     End If
  19.  
  20.     strCriteria = Right(strCriteria, Len(strCriteria) - 1)
  21.  
  22.     strSQL = "SELECT * FROM qrySTMTMM " & " WHERE [qdfMULTI.CustID] IN (" & strCriteria & ");"
  23.  
  24.     STMT2.SQL = strSQL
  25.  
  26.     DoCmd.OpenQuery "MMSGSummaryMULTI"
  27.     Set ms = Nothing
  28.     Set STMT2 = Nothing
  29. End Sub
when I hover over the error, I get
STMT2: The correct query and columns show...including CustID
strSQL: strSQL = "SELECT * FROM qrySTMTMM " & " WHERE [qdfMULTI.CustID] IN (100',102');"
Feb 14 '19 #1
1 1331
twinnyfo
3,653 Recognized Expert Moderator Specialist
MC42015,

It depends on if your values are supposed to be numeric or strings. It should look this way for numeric:

Expand|Select|Wrap|Line Numbers
  1. [qdfMulti].[CustID] In (100, 102)
And this way for strings:

Expand|Select|Wrap|Line Numbers
  1. [qdfMulti].[CustID] In (‘100’, ‘102’)
Whatever code you are using to create your criteria string must come up with those values.

Hope this hepps!
Feb 14 '19 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
3551
by: theoryboy | last post by:
I'm trying to implement multiple selection functionality in a Tix Hlist using a control-click. I've bound control-click to a function that uses selection_set to add to the selection, but it doesn't...
2
6350
by: Sally | last post by:
I have a simple multiselect listbox with a rowsorce of MemberID, MemberName, SendLetter. SendLetter is a Yes/No field. What is the code to set SendLetter to Yes when the user selects MemberName? I...
18
3321
by: Alpha | last post by:
Hi, I'm working on a Windows applicaton with VS 2003 on windows 2000. I have a listbox that I have binded to a dataset table, "source" which has 3 columns. I would like to display 2 of those...
0
2031
by: bill yeager | last post by:
Duray, it helps in regards to knowing how to get the items that were selected in the lisbox, but I'm going in reverse --- after I get the items from the db that were selected, I'd like to be able...
3
1303
by: Paul W | last post by:
I am populating listbox with a datreader. DateReader sqlcommand is dynamic, based on several user selections Listbox DataValueField is set to the tables primary key Listbox DataTextField is...
6
2858
by: Chris Leuty | last post by:
I am populating a multiselect Listbox from a dataset, with the content of the listbox filled by one table, and the selections determined from another table. So far, I have been keeping the dataset...
0
1264
by: Ken Varn | last post by:
I have a strange problem with a databound listbox. It may be because of how I use it, but I am stumped by this behavior. Here is the scenario: I have a multiselect databound listbox that...
2
3012
by: ProgrammerChicago | last post by:
I'm not sure if this is the result of the postback behavior or my own code, but for some reason my onclick function is not detecting listbox selections (It's meant to delete files uploaded to the...
6
3359
by: BerkshireGuy | last post by:
On an unbound form, I have a combobox called 'cboproducttype' and a text box called 'txtamountappliedfor'. I have an Add button that I would like the user to be able to hit once a product and...
4
1432
by: kimiraikkonen | last post by:
Hi, I have a odd but a known question about listbox. I know listbox control can provide multi-select, multi-extendend selections. But i wonder if this selection type belongs to them or it has...
0
7267
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7175
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7553
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7120
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7542
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
3247
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1609
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
809
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
466
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.