473,414 Members | 1,688 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,414 software developers and data experts.

Listbox Columns INSERT into Table, HALP!

gcoaster
117 100+
Hello Scripts gurus

I am Filling a Listbox with combo box values
the listbox is showing multiple values
what I am trying to do is get these values to
INSERT into a table!! this code only inserts one.


Thank you in advance,

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdAddProd_Click()
  2. If IsNull(Me.lstAddedProd) And Not IsNull(Me.lstProduct) Then
  3.  
  4.  
  5. Dim db As DAO.Database
  6. Dim rs As DAO.Recordset
  7.  
  8. Set rs = Me.RecordsetClone
  9.  
  10.   With rs
  11.  
  12.     .AddNew
  13.  
  14.     !productName = Me.lstProduct.Column(1)
  15.     !UnitPrice = Me.lstProduct.Column(2)
  16.  
  17.     .Update
  18.  
  19.   End With
  20.  
  21.    Me.lstAddedProd.Requery
  22.    Me.lstProduct.Requery
  23.  
  24.    Me.lstAddedProd = Null
  25.    Me.lstProduct = Null
  26.  
  27. Set rs = Nothing
  28.  
  29.   End If
  30.  
  31. End Sub
  32.  
Nov 21 '07 #1
6 9042
JustJim
407 Expert 256MB
Hello Scripts gurus

I am Filling a Listbox with combo box values
the listbox is showing multiple values
what I am trying to do is get these values to
INSERT into a table!! this code only inserts one.


Thank you in advance,

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdAddProd_Click()
  2. If IsNull(Me.lstAddedProd) And Not IsNull(Me.lstProduct) Then
  3.  
  4.  
  5. Dim db As DAO.Database
  6. Dim rs As DAO.Recordset
  7.  
  8. Set rs = Me.RecordsetClone
  9.  
  10.   With rs
  11.  
  12.     .AddNew
  13.  
  14.     !productName = Me.lstProduct.Column(1)
  15.     !UnitPrice = Me.lstProduct.Column(2)
  16.  
  17.     .Update
  18.  
  19.   End With
  20.  
  21.    Me.lstAddedProd.Requery
  22.    Me.lstProduct.Requery
  23.  
  24.    Me.lstAddedProd = Null
  25.    Me.lstProduct = Null
  26.  
  27. Set rs = Nothing
  28.  
  29.   End If
  30.  
  31. End Sub
  32.  
Have a look here for a brief discussion about getting all the selected data out of a multiselect listbox.

Have fun

Jim
Nov 21 '07 #2
gcoaster
117 100+
Have a look here for a brief discussion about getting all the selected data out of a multiselect listbox.
Have fun
Jim
I will have FUN when this is working! ;-)
I see, thank you for that, it is telling me my method is not the best..

is this close?
Expand|Select|Wrap|Line Numbers
  1. Dim valSelect As Variant
  2. Dim strValue As String ' just used for the demonstration
  3.  
  4.     For Each valSelect In Me.lstProduct.ItemsSelected
  5.         strValue = strValue & "'" & Me.lstProduct.ItemData(valSelect) & "', "
  6.     Next valSelect
  7.  
  8. End Sub
I also found this method on this brilliant forum

Expand|Select|Wrap|Line Numbers
  1.         Private Sub cmdSubmit_Click()
  2.         Dim valSelect As Variant
  3.         Dim strSQL As String
  4.  
  5.            For Each valSelect In Me.listboxName.ItemsSelected
  6.               strSQL = "INSERT INTO Interest (applicantID, officeID) VALUES (" & _
  7.               Me.applicantID & ", " & Me.listboxName.ItemData(valSelect) & ")"
  8.            Next valSelect
  9.  
  10.            Me.SubformObjectName.Requery
  11.  
  12.         End Sub
Nov 21 '07 #3
JustJim
407 Expert 256MB
I will have FUN when this is working! ;-)
I see, thank you for that, it is telling me my method is not the best..

is this close?
Expand|Select|Wrap|Line Numbers
  1. Dim valSelect As Variant
  2. Dim strValue As String ' just used for the demonstration
  3.  
  4.     For Each valSelect In Me.lstProduct.ItemsSelected
  5.         strValue = strValue & "'" & Me.lstProduct.ItemData(valSelect) & "', "
  6.     Next valSelect
  7.  
  8. End Sub
I also found this method on this brilliant forum

Expand|Select|Wrap|Line Numbers
  1.         Private Sub cmdSubmit_Click()
  2.         Dim valSelect As Variant
  3.         Dim strSQL As String
  4.  
  5.            For Each valSelect In Me.listboxName.ItemsSelected
  6.               strSQL = "INSERT INTO Interest (applicantID, officeID) VALUES (" & _
  7.               Me.applicantID & ", " & Me.listboxName.ItemData(valSelect) & ")"
  8.            Next valSelect
  9.  
  10.            Me.SubformObjectName.Requery
  11.  
  12.         End Sub
The first method builds up a string made up of all the selected values in the multi select list box (don't forget to get rid of the trailing comma) and you could use this string to add data to your table.

The second method builds up a string of SQL code that would run an append query to add data to your table.

The choice is yours - I'm not competent to comment on the efficiency of either method.

Jim
Nov 21 '07 #4
gcoaster
117 100+
The first method builds up a string made up of all the selected values in the multi select list box (don't forget to get rid of the trailing comma) and you could use this string to add data to your table.

The second method builds up a string of SQL code that would run an append query to add data to your table.

The choice is yours - I'm not competent to comment on the efficiency of either method.

Jim
Thank You Jim,

Where would I insert the INSERT?

INSERT into tblINVOICEDETAILS
Nov 21 '07 #5
JustJim
407 Expert 256MB
Thank You Jim,

Where would I insert the INSERT?

INSERT into tblINVOICEDETAILS
Put a command button near the multiselect list box so that your users can click on it after they have made their selections. Put the code that builds up the SQL INSERT INTO string in the On-Click event of that button. You will also need the RunSQL method of the DoCmd object.

Jim
Nov 21 '07 #6
gcoaster
117 100+
Put a command button near the multiselect list box so that your users can click on it after they have made their selections. Put the code that builds up the SQL INSERT INTO string in the On-Click event of that button. You will also need the RunSQL method of the DoCmd object.

Jim
Thank you Jim, that really helped me. you guys are the best!
Nov 28 '07 #7

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

Similar topics

5
by: Andrew | last post by:
Hi I just started learning wxPython I wanted to know how I could do this in wxPython self.listbox.delete(0, END) for item in self.results: self.listbox.insert(END, item)
6
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...
3
by: Eric Lemmon | last post by:
Greetings, I have a VB.NET Windows app where I bind a listbox to a DataView column that contains date values. In this list, however, only the date (not the time) is relavent, so I want to...
28
by: cjobes | last post by:
Hi all, I need to populate a listbox from a table column. The column has multiple entries of usernames and I need to pull a unique set of usernames. The table is part of an untyped Dataset that...
5
by: Dave | last post by:
Hi All, I have a windows form that contains 2 listboxes and 2 buttons. The listbox on the right is populated by a database routine (This is the easy part). The listbox on the left is populated...
1
by: eric | last post by:
Hi, Can anyone please explain to me how I can cop selected items from a multi listbox(simple) to another multi listbox? the code I found on msdn only seems to support single column copies, i...
9
by: serge | last post by:
/* Subject: How to build a procedure that returns different numbers of columns as a result based on a parameter. You can copy/paste this whole post in SQL Query Analyzer or Management Studio...
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: troy_lee | last post by:
I have a form that screens the database. I build a dynamic WHERE clause into a string and apply it to the form's filter. I want to allow the user to save, say, five or 10 of their most-used...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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
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
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.