473,497 Members | 2,190 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to run an update query on a multiselect list box

137 New Member
What I'm trying to do is to update a numerical value on all the records selected in the multiselect listbox.

I'm not entirely sure if what I'm trying to do is the correct way of doing it, but the code I'm trying is:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Save_Click()
  2. Dim varItem As Variant
  3.  
  4. For Each varItem In Me.ProgramList.ItemsSelected
  5. strSQL = "UPDATE tblPrograms SET tblPrograms.Client_ID =" & Me.ClientList.Column(1) & _
  6.          " WHERE tblPrograms.Program =" & varItem
  7. DoCmd.RunSQL strSQL
  8. Next varItem
The code keeps triggering a Data mismatch error, even though both data types used in this query are numerical - changing the code as though they were text fields still triggers a data mismatch error.

Any ideas how to fix this?

Thanks.
Apr 4 '11 #1
4 3417
Mariostg
332 Contributor
Probably because varItem is declared as a Variant. You probably need to cast it as in integer: cint(varItem)
Apr 4 '11 #2
Adam Tippelt
137 New Member
Gives an error if I change it to integer, saying that it must be either Variant or Object.

Perhaps there's another way to code it? All I'm trying to do is update a column for all the selected options in the list box.
Apr 5 '11 #3
Mariostg
332 Contributor
Maybe I should have been clearer.
The casting should be in
Expand|Select|Wrap|Line Numbers
  1. " WHERE tblPrograms.Program =" & cint(varItem)
  2.  
. To iterate over the for each, varItem must be a variant, but your query is expecting an integer I presume.
Apr 5 '11 #4
Adam Tippelt
137 New Member
Oh right, that makes more sense.

Turned out my problem was that I was referencing the wrong column in the table - Program instead of Program_ID, so was looking at a text field.

Thanks for your help - I get the feeling you've pre-emptively fixed another problem I would have run into anyway.
Apr 5 '11 #5

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

Similar topics

4
6342
by: Jon McLean | last post by:
I fear that my question may be elementary, but what I am trying just is not working. I have two tables: tblContacts (Essentially a mailing list. Each contact has an Autonumber ID.)...
7
2566
by: Dave Hopper | last post by:
Hi I posted a question recently regarding problems I am having getting a value from a list box to use in a query. I got a lot of help, for which I thank you and it's nearly working! But I need...
1
8579
by: Jillian Cee | last post by:
I have a multiselect list box (simple). I need to find out how to get Access to recognise my multiple selections firstly (I believe) then I want these selections to go into a query so that I can...
5
4671
by: Andrew | last post by:
I've got a list box that selects a record on a subform, and in that subform are a few text fiels and a button that runs an update query. How do I have the update query button run and only update...
3
2575
by: Shannan Casteel via AccessMonster.com | last post by:
I have three main tables. The first is the table that my main form will be based on. This is where the user will enter all the data. The table is called TechnicalProblemsTable. It looks like...
2
1943
by: Steph | last post by:
I have created a multiselect list box control (lbx_comorb) that is populated from a datatable (dt_ptAdmission). The list box populates now problem at all. However the issue is when I load the...
3
2355
by: John | last post by:
Hi I am using the following get the items from a multiselect list; Dim ctl As Control For Each ctl In Me.BatchInvoicesList.ItemsSelected Problem is that I am getting a 'Object not found...
3
2165
by: rdraider | last post by:
Hi all, Any thoughts on the best way to run an update query to update a specific list of records where all records get updated to same thing. I would think a temp table to hold the list would be...
1
3018
by: kak36 | last post by:
Hello and Help, Please. Using Access 2003, I am using a Multiselect List Box (simple) in the data entry window. Thanks to this site, I have created a Current Event to show the selected answer in a...
13
4140
by: Neil | last post by:
I'm running an update query in SQL 7 from QA, and it runs forever. Has been running for 20 minutes so far! The query is quite simple: update a single field in a table, based on a join with another...
0
6991
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
7196
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
6878
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
5456
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4897
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3088
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
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1405
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 ...
0
286
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.