472,353 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Trouble with Simple Multi Select Listbox in Access 2003 (not so simple for me)

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 record to be written over and
over, for example if I have 4 items selected, it writes the same item 4
times in my table.

Here is my code.

Private Sub OrderRxs_Click()

Dim db As DAO.Database
Dim rstOrder As DAO.Recordset
Dim varItem As Variant

OrderGroupNumber = DMax("[OrderGroupID]", "[RefillOrders_Info]") +
1

If ListBox.ItemsSelected.Count = 0 Then
MsgBox "You must select Rx Numbers to Order.", vbExclamation +
vbOKOnly
Exit Sub
Else
bytChoice1 = MsgBox("Order " & ListBox.ItemsSelected.Count & "
Rx(s) for Paitent?", vbInformation + vbYesNo)
If bytChoice1 = vbNo Then
Exit Sub
End If
If bytChoice1 = vbYes Then
Set db = CurrentDb
Set rstOrder = db.OpenRecordset("RefillOrders_Info")

With rstOrder
For Each varItem In ListBox.ItemsSelected
.AddNew
![OrderGroupID] = OrderGroupNumber
![Patient Code] = ListBox.Column(1)
![Pat Last Name] = ListBox.Column(2)
![Pat First Nme] = ListBox.Column(3)
![EmployeeID] = lngCurrentEmpID
.Update
Next varItem
End With
End If
End If

rstOrder.Close
Set rstOrder = Nothing
db.Close
Set db = Nothing
End Sub

I would love some help with my mess!!!

thanks,
Lisa

Nov 13 '05 #1
5 6244
Br
In news:11*********************@g14g2000cwa.googlegro ups.com,
Lisa <li*******@aol.com> said:
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 record to be written
over and over, for example if I have 4 items selected, it writes the
same item 4 times in my table.

Here is my code.

Private Sub OrderRxs_Click()

Dim db As DAO.Database
Dim rstOrder As DAO.Recordset
Dim varItem As Variant

OrderGroupNumber = DMax("[OrderGroupID]", "[RefillOrders_Info]") +
1

If ListBox.ItemsSelected.Count = 0 Then
MsgBox "You must select Rx Numbers to Order.", vbExclamation +
vbOKOnly
Exit Sub
Else
bytChoice1 = MsgBox("Order " & ListBox.ItemsSelected.Count & "
Rx(s) for Paitent?", vbInformation + vbYesNo)
If bytChoice1 = vbNo Then
Exit Sub
End If
If bytChoice1 = vbYes Then
Set db = CurrentDb
Set rstOrder = db.OpenRecordset("RefillOrders_Info")

With rstOrder
For Each varItem In ListBox.ItemsSelected
.AddNew
![OrderGroupID] = OrderGroupNumber
![Patient Code] = ListBox.Column(1)
![Pat Last Name] = ListBox.Column(2)
![Pat First Nme] = ListBox.Column(3)
![EmployeeID] = lngCurrentEmpID
.Update
Next varItem
End With
End If
End If

rstOrder.Close
Set rstOrder = Nothing
db.Close
Set db = Nothing
End Sub

I would love some help with my mess!!!

thanks,
Lisa

Nov 13 '05 #2
Br
In news:11*********************@g14g2000cwa.googlegro ups.com,
Lisa <li*******@aol.com> said:
<>
With rstOrder
For Each varItem In ListBox.ItemsSelected
.AddNew
![OrderGroupID] = OrderGroupNumber
![Patient Code] = ListBox.Column(1)
![Pat Last Name] = ListBox.Column(2)
![Pat First Nme] = ListBox.Column(3)
![EmployeeID] = lngCurrentEmpID
.Update
Next varItem
End With
End If
End If


You're not referencing the selected item correctly.

eg.

![Patient Code] = ListBox.Column(1)

Should be..

![Patient Code] = ListBox.Column(1, varItem)

What you are doing is getting the bound value only which is the current
selected record.

Check out the Access help for "ItemsSelected" and check the Example,
it's all there :)

Br@Dley
Nov 13 '05 #3
Instead of Column(1), try Column(1, varItem).

James A. Fortune

Nov 13 '05 #4
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You have to indicate which row in the ListBox the data comes from. You
used varItem. I usually use a variable named "row."

Dim row Variant
For Each row In ListBox.ItemsSelected
.AddNew
![OrderGroupID] = OrderGroupNumber
![Patient Code] = ListBox.Column(1,row)
![Pat Last Name] = ListBox.Column(2,row)
![Pat First Nme] = ListBox.Column(3,row)
![EmployeeID] = lngCurrentEmpID
.Update
Next row
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQmhd2YechKqOuFEgEQJiFACg3qVL0f0FZL2F4nV2HlCBcS BiNmsAn0JU
XkKJe9ordHI7iAGNIlFZaNEZ
=wzy9
-----END PGP SIGNATURE-----
Lisa wrote:
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 record to be written over and
over, for example if I have 4 items selected, it writes the same item 4
times in my table.

Here is my code.

Private Sub OrderRxs_Click()

Dim db As DAO.Database
Dim rstOrder As DAO.Recordset
Dim varItem As Variant

OrderGroupNumber = DMax("[OrderGroupID]", "[RefillOrders_Info]") +
1

If ListBox.ItemsSelected.Count = 0 Then
MsgBox "You must select Rx Numbers to Order.", vbExclamation +
vbOKOnly
Exit Sub
Else
bytChoice1 = MsgBox("Order " & ListBox.ItemsSelected.Count & "
Rx(s) for Paitent?", vbInformation + vbYesNo)
If bytChoice1 = vbNo Then
Exit Sub
End If
If bytChoice1 = vbYes Then
Set db = CurrentDb
Set rstOrder = db.OpenRecordset("RefillOrders_Info")

With rstOrder
For Each varItem In ListBox.ItemsSelected
.AddNew
![OrderGroupID] = OrderGroupNumber
![Patient Code] = ListBox.Column(1)
![Pat Last Name] = ListBox.Column(2)
![Pat First Nme] = ListBox.Column(3)
![EmployeeID] = lngCurrentEmpID
.Update
Next varItem
End With
End If
End If

rstOrder.Close
Set rstOrder = Nothing
db.Close
Set db = Nothing
End Sub

I would love some help with my mess!!!

thanks,
Lisa

Nov 13 '05 #5
I came to the right place for help! That worked perfectly. If I could
wrap my arms around you all I would give you a big hug :)

Thanks so much for your expertise!
Lisa

Nov 13 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Eddie Smit | last post by:
field- field- surname town ---- ---- john NY john Vegas john Boston eddie Boston eddie New Orleans eddie NY
2
by: Hi5 | last post by:
Hi, Is there any chance of getting to know how to make a drop down as a Multi select list boxes in Access? Many Thanks
0
by: Park via AccessMonster.com | last post by:
I am new to Access and am having a problem with a simple listbox. This listbox is in a subform and contains 5 options. I entered these in a value...
18
by: Alpha | last post by:
Hi, I'm working on a Windows applicaton with VS 2003 on windows 2000. I have a listbox that I have binded to a dataset table, "source" which has 3...
2
by: Zlatko Matić | last post by:
Hello. How to reference selected values from a multi-select list box, as a criteria in a query ? Is it possible at all? Regards, Zlatko
17
by: Redbeard | last post by:
I am a newbie that is running Access 2003. I am trying to have a multi select listbox run a query that filter a form. I have tried several codes off...
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...
36
by: aaronkmar | last post by:
Hello Bytes, I've been a long time lurker, there so much information here I always find my answers with ease. Until today... I'm hoping...
5
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

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.