473,411 Members | 2,186 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,411 software developers and data experts.

Moving data from a list box to a table

Hi,

I have a list box that allows you to select multiple values and then transfers the selected values to a table.

I have almost cracked this but I am having a small problem;

My code is as follows;

Private Sub Command18_Click()
Dim item
Dim dbSOWGen As DAO.Database
Dim rstNewSOW As DAO.Recordset

Set dbSOWGen = CurrentDb
Set rstNewSOW = dbSOWGen.OpenRecordset("TABLE SOW")

For Each item In List6.ItemsSelected
rstNewSOW.AddNew
rstNewSOW("Description").Value = List6.ItemData(item)
rstNewSOW("PPU").Value = List6.Column(1, List6.ListIndex)
rstNewSOW("Hours").Value = List6.Column(2, List6.ListIndex)
rstNewSOW("Type").Value = "SOW"
rstNewSOW("Task Number").Value = [Task Number]
rstNewSOW.Update
Next item

Forms("FORM_PriceBooks").[TABLE SOW subform1].Requery

DoCmd.Close
End Sub

It is successfully transfering the Descriptions selected values but it is only transferring the last selected values for PPU and Hours. Can someone please help me modify the above code so it transfers the correct values for PPU and Hours as it runs through the FOR loop???

Any help will be really appreciated

RichO
Mar 12 '08 #1
4 5254
JustJim
407 Expert 256MB
Hi,

I have a list box that allows you to select multiple values and then transfers the selected values to a table.

I have almost cracked this but I am having a small problem;

My code is as follows;

Private Sub Command18_Click()
Dim item
Dim dbSOWGen As DAO.Database
Dim rstNewSOW As DAO.Recordset

Set dbSOWGen = CurrentDb
Set rstNewSOW = dbSOWGen.OpenRecordset("TABLE SOW")

For Each item In List6.ItemsSelected
rstNewSOW.AddNew
rstNewSOW("Description").Value = List6.ItemData(item)
rstNewSOW("PPU").Value = List6.Column(1, List6.ListIndex)
rstNewSOW("Hours").Value = List6.Column(2, List6.ListIndex)
rstNewSOW("Type").Value = "SOW"
rstNewSOW("Task Number").Value = [Task Number]
rstNewSOW.Update
Next item

Forms("FORM_PriceBooks").[TABLE SOW subform1].Requery

DoCmd.Close
End Sub

It is successfully transfering the Descriptions selected values but it is only transferring the last selected values for PPU and Hours. Can someone please help me modify the above code so it transfers the correct values for PPU and Hours as it runs through the FOR loop???

Any help will be really appreciated

RichO
Hi,
Completely off the top of my head, I think it's in the DIM of Item. I think it's got to be a special data type, not just Variant. I'll look into it a bit later and get back to you.

You are very close though.

Jim
Mar 20 '08 #2
JustJim
407 Expert 256MB
Me again,

No, it seems that Variant is fine. While I work this through, have a look at this

Jim
Mar 20 '08 #3
ADezii
8,834 Expert 8TB
Hi,

I have a list box that allows you to select multiple values and then transfers the selected values to a table.

I have almost cracked this but I am having a small problem;

My code is as follows;

Private Sub Command18_Click()
Dim item
Dim dbSOWGen As DAO.Database
Dim rstNewSOW As DAO.Recordset

Set dbSOWGen = CurrentDb
Set rstNewSOW = dbSOWGen.OpenRecordset("TABLE SOW")

For Each item In List6.ItemsSelected
rstNewSOW.AddNew
rstNewSOW("Description").Value = List6.ItemData(item)
rstNewSOW("PPU").Value = List6.Column(1, List6.ListIndex)
rstNewSOW("Hours").Value = List6.Column(2, List6.ListIndex)
rstNewSOW("Type").Value = "SOW"
rstNewSOW("Task Number").Value = [Task Number]
rstNewSOW.Update
Next item

Forms("FORM_PriceBooks").[TABLE SOW subform1].Requery

DoCmd.Close
End Sub

It is successfully transfering the Descriptions selected values but it is only transferring the last selected values for PPU and Hours. Can someone please help me modify the above code so it transfers the correct values for PPU and Hours as it runs through the FOR loop???

Any help will be really appreciated

RichO
The following code segment should work well for you, just be sure to substitute your Form's Name for the place marker in Line# 7:
Expand|Select|Wrap|Line Numbers
  1. Dim frm As Form
  2. Dim ctl As Control
  3. Dim intCounter As Counter
  4. Dim dbSOWGen As DAO.Database
  5. Dim rstNewSOW As DAO.Recordset
  6.  
  7. Set frm = Forms!("<your Form Name here>")
  8. Set ctl = frm![List6]
  9.  
  10. Set dbSOWGen = CurrentDb
  11. Set rstNewSOW = dbSOWGen.OpenRecordset("TABLE SOW")
  12.  
  13. If ctl.ItemsSelected.Count > 0 Then
  14.   For intCounter = 0 To ctl.ItemsSelected.Count - 1
  15.     rstNewSOW.AddNew
  16.       rstNewSOW("Description") = ctl.Column(0, intCounter)
  17.       rstNewSOW("PPU") = ctl.Column(1, intCounter)
  18.       rstNewSOW("Hours") = ctl.Column(2, intCounter)
  19.       rstNewSOW("Type") = "SOW"
  20.       rstNewSOW("Task Number") = Me![Task Number]
  21.     rstNewSOW.Update
  22.   Next intCounter
  23. End If
  24.  
  25. rstNewSOW.Close
  26. Set rstNewSOW = Nothing
  27.  
  28. Forms("FORM_PriceBooks").[TABLE SOW subform1].Requery
  29.  
  30. DoCmd.Close
Mar 20 '08 #4
Thank you both for your help. The last post is exactly what I was looking for. Once again thanks tonnes I really appreciate your assistance.

Regards,

RichO
Apr 7 '08 #5

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

Similar topics

6
by: Stephen Miller | last post by:
Firstly, sorry for the long post, but I've included a fair bit of sample data. Im doing a comparision of 10yr Bond prices and CPI adjustments, with an 18 week moving average of the CPI. I'm...
5
by: Christian Traber | last post by:
Hi! just playing with tablespaces... - moved a existing table to a new tablespace - tried to move it back to default tablespace (ALTER TABLE accounts SET TABLESPACE pg_default;) Got the...
3
by: Iavor Raytchev | last post by:
Hello, We a situation with a central database that contains the data that needs to be presented at N off-line terminals (N can be 5 000 can be 15 000). Each terminal presents unique data. The...
2
by: fuzzybr80 | last post by:
I am using MySQL 5.0 with a number of innodb tables whose ibdata files are growing quite quickly and filling up the /var partition (file is /var/mysql/ibdata1). Earlier on I followed instructions...
14
by: rabbitrun | last post by:
Hi Everyone, I work for a financial company. I am planning to give a presentation to rest of the development team (15 people) here on moving server side logic to client-side javascript for an...
3
prn
by: prn | last post by:
Hi folks, I've got something that's driving me crazy here. If you don't want to read a long explanation, this is not the post for you. My problematic Access app is a DB for keeping track of...
1
by: madflytom | last post by:
Hello, I'm trying to move the options of one select list to another select list. The "source" select list is divided into optgroups, and the "target" select list is not. I want to somehow keep...
0
by: SuzK | last post by:
I am trying to calculate in VBA in Access 2002 a moving average and update a table with the calculations. Fields in my WeeklyData table are Week Ending (date) ItemNbr (double) Sales Dollars...
3
by: c0l0nelFlagg | last post by:
I have a moving dispatcher database. There are 99 drivers, 99 loaders, and 50 different vehicles. The scheduler database is built on a 13 4 week month year so that it can be used repeatedly in any...
3
JodiPhillips
by: JodiPhillips | last post by:
Hello everyone, there are many questions and answers relating to moving items between two listboxes here and on the net in general, however, none answer my specific problem. I have two listboxes...
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
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
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
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
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...
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.