473,406 Members | 2,633 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Select Multivalues in listbox

Hi
i have a listbox that generate years. i want to be able to selct one or more years. i change the properties of multi selct to extended and i can select more than one. but the problem is that i want to pass the data in to the table in sql database and it is not passing .

i would appreciate any help.

thanks
voroojak
Mar 4 '09 #1
7 1532
Stewart Ross
2,545 Expert Mod 2GB
Hi. You will need to loop through each of the values selected from your listbox and use a suitable SQL INSERT statement generated in code to insert them one by one into the table concerned. You tell us too little to give you much that will help you with this task, but the following skeleton may give you some ideas:

Expand|Select|Wrap|Line Numbers
  1. Dim ctl as Control
  2. Dim varItm as Variant
  3. Dim strSQL as String
  4. Set ctl = Me![name of your listbox]
  5. For Each varItm In ctl.ItemsSelected
  6.         strSQL = "INSERT INTO [your table name] ([your field name 1]) "
  7.         strSQL = strSQL & " VALUES " & ctl.ItemData(varItm) & ";"
  8.         CurrentDb.Execute strSQL
  9. Next varItm
You may find that you need to give all of this much more thought. I see little value in inserting single values like this into new rows in a table (assuming that you are not violating key contraints by doing so), but without knowing more details all I can do is answer the question you have actually asked, not the ones I think you should have asked.

Maybe you really mean you want to update existing rows, in which case you would use an UPDATE statement in place of the INSERT, but you would have to have suitable selection criteria to update the correct records. Anyway, you don't tell us, and there is simply not enough detail in what you ask to advise you further.

-Stewart
Mar 4 '09 #2
HI
thanks for your answer.the thing is that i want to select multivalues from my listbox and then i can be able to show the selected values in my table. for example if i choos 2009 and 2010, then it shows in my table 2009 2010.

thanks alot
Mar 4 '09 #3
Stewart Ross
2,545 Expert Mod 2GB
Sorry, but I have no idea what you mean by 'show the selected values in my table'. Are you really meaning the table, or do you mean the form itself?

If you really do mean table, is it the table to which your form is bound? Is it some other table? If it is, you either want to INSERT a row into your table to contain the values, or UPDATE an existing row with those values - what other choices are there?

I am thoroughly confused over what you are really asking...

-Stewart
Mar 4 '09 #4
I am really sorry if i confuse you.
i try to fix it.
maybe it is better just to say that i have a table that i called campaign_data
and the column that the year should be pass is year_list. the list box name is yr_list.
what i want to have as a result is that if i select 2009 and 2010 in my list box, the value that i can see in my table be 2009 2010.

thanks alot
Mar 5 '09 #5
H again
it worked some how.
i did with check box and put the conditions whether it is checked or not. i was prefering to do it with list box but it didnt work unfortunately. i still like to know how can i do it with list box but for now it is working:)

thanks alot
Mar 5 '09 #6
Stewart Ross
2,545 Expert Mod 2GB
Hi voroojak. Thanks for your clarification. You were referring to the table bound to the form itself, a point not clear from your question. The solution given by me in post # 2 is referring to inserting rows in a completely independent table from an unbound listbox control, and it just does not apply to your circumstances as we now know them. A bound listbox control updates a value in the underlying table as soon as a selection is made from the control.

I am sure next time you post you will be clearer about such details.

Glad whatever was wrong is now working for you.

-Stewart
Mar 5 '09 #7
Thanks alot and sorry for not be cleared.
Mar 5 '09 #8

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

Similar topics

4
by: headware | last post by:
I have a <select> control that contains many entries. It allows the user to multi-select a group of them, click a button, and store the selected data in a database. Normally they do this starting...
4
by: Alienz | last post by:
I have a subform where I have a subform with 20 options to select from. When I set the multiselect property to simple and select multiple options, nothing is stored. I have another table with...
5
by: Lisa | last post by:
Hello, I am new to using recordsets, and i am completly stuck with this one. I am trying to use a multi select list box to write records to a table. Something in my code is causing the same...
1
by: Ahmet Karaca | last post by:
Hi. myds.Reset(); mycommand.SelectCommand.CommandText= "Select att1 from Ing as Ingredient, Pro as Product "+ "where Pro.ad='apple' and Pro.id=Ing.id"; mycommand.Fill(myds, "Product"); // Here...
5
by: Matthew Wells | last post by:
I have a listbox set to simple multi select. For this example, users only select one item at a time. I have command buttons on the form for First, Previous, Next, Last, New (record). The form...
1
by: Sunray | last post by:
I have a form called the sales form and i have 2 sets of listboxes So what happens is. i add items form the bottom set of list boxes which are bound to a data base to the top set of list boxes which...
2
by: billa856 | last post by:
Hi, My Project is in MS Access. In that I have one form in which I have some textboxes,comboboxes and listboxes. Now when I select value from 1st combobox(CustomerID) then it wil generate list for...
4
by: Vincent | last post by:
I have a list box that is bound to a table with many records. I have a select all button that when clicked, obviously, selects all of the items in the list box. However, it takes a fairly long...
17
by: trose178 | last post by:
Good day all, I am working on a multi-select list box for a standard question checklist database and I am running into a syntax error in the code that I cannot seem to correct. I will also note...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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,...
0
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...

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.