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
4 5254
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
Me again,
No, it seems that Variant is fine. While I work this through, have a look at this
Jim
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: -
Dim frm As Form
-
Dim ctl As Control
-
Dim intCounter As Counter
-
Dim dbSOWGen As DAO.Database
-
Dim rstNewSOW As DAO.Recordset
-
-
Set frm = Forms!("<your Form Name here>")
-
Set ctl = frm![List6]
-
-
Set dbSOWGen = CurrentDb
-
Set rstNewSOW = dbSOWGen.OpenRecordset("TABLE SOW")
-
-
If ctl.ItemsSelected.Count > 0 Then
-
For intCounter = 0 To ctl.ItemsSelected.Count - 1
-
rstNewSOW.AddNew
-
rstNewSOW("Description") = ctl.Column(0, intCounter)
-
rstNewSOW("PPU") = ctl.Column(1, intCounter)
-
rstNewSOW("Hours") = ctl.Column(2, intCounter)
-
rstNewSOW("Type") = "SOW"
-
rstNewSOW("Task Number") = Me![Task Number]
-
rstNewSOW.Update
-
Next intCounter
-
End If
-
-
rstNewSOW.Close
-
Set rstNewSOW = Nothing
-
-
Forms("FORM_PriceBooks").[TABLE SOW subform1].Requery
-
-
DoCmd.Close
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
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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,...
|
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: 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...
| |