| Author |
Topic Search Topic Options
|
ziwez0
Groupie
Joined: 15 July 2002
Location: United Kingdom
Status: Offline
Points: 144
|
Post Options
Thanks(0)
Quote Reply
Topic: Anyone know much about access programming Posted: 14 October 2003 at 10:34am |
Ive been playing around with programming in access recently but have come across a stumble block,
i have two tables one that contains dates and the other contains customer information (fname lname dob etc)
i have a form(called form1) that has a drop drop down box that connects to the first table (dates) and have a list box thats contains the customer info, basically when you select a date from the drop down box it then looks up the customer info table and sees what customers are in on that date and then displays in in the list box.
so..
it all works fine but it only displays the first name of the customer, where i want it to displat the first name, last name and party name.
here is the code
List2.RowSource = "Select [First Name], [Last Name], [Party Name] from [new diver] where [new diver].[check in]=[Forms]![Form1]![Combo0];"
any help on this would be great!
|
|
If anything takes long to do its worth doing.
|
 |
Bunce
Senior Member
Joined: 10 April 2002
Location: Australia
Status: Offline
Points: 846
|
Post Options
Thanks(0)
Quote Reply
Posted: 16 October 2003 at 4:24am |
If you bring up the properties of the list box, there should be an option for setting the number of columns to display. Change that to 3/4 and you should be right.
Cheers, Andrew
|
|
There have been many, many posts made throughout the world...
This was one of them.
|
 |
ziwez0
Groupie
Joined: 15 July 2002
Location: United Kingdom
Status: Offline
Points: 144
|
Post Options
Thanks(0)
Quote Reply
Posted: 16 October 2003 at 4:29am |
cheers Andrew, worked that one out this morning,
just a another question, do you know how to get mutilple values from one list box, click a button and it will add it into a second list box, if it had a remove button to that would be good..
thanks.
|
|
If anything takes long to do its worth doing.
|
 |
Bunce
Senior Member
Joined: 10 April 2002
Location: Australia
Status: Offline
Points: 846
|
Post Options
Thanks(0)
Quote Reply
Posted: 16 October 2003 at 4:38am |
From memory, it stores your selected values in an array called somethng like listbox.selecteditems() or something.
So with button_onclick() event, you'll need to iterate through that array, and apply it to the recordsource of your second listbox.
Can't recall much more than that without going into Access. Check out Access help for how your selected values are stored in a list box and see if you can work it out from there.
If not, report back and let me know.
Cheers, A
Edited by Bunce
|
|
There have been many, many posts made throughout the world...
This was one of them.
|
 |
Bunce
Senior Member
Joined: 10 April 2002
Location: Australia
Status: Offline
Points: 846
|
Post Options
Thanks(0)
Quote Reply
Posted: 16 October 2003 at 4:49am |
oops, rather than apply it to the recordsource of your second listbox, you would need to use the 'addItem' method of the second listbox, and add them one at a time as you iterate through that array/collection of selecteditems.
Cheers, Andrew
|
|
There have been many, many posts made throughout the world...
This was one of them.
|
 |
Bunce
Senior Member
Joined: 10 April 2002
Location: Australia
Status: Offline
Points: 846
|
Post Options
Thanks(0)
Quote Reply
Posted: 16 October 2003 at 4:57am |
OK. I got curious and had to have a look!! I was close..
The selected items are held in a collection which you can get at by using: ListBox1.ItemsSelected
So you need to iterate through these items using: For Each SelItem in Listbox1.ItemsSelected
To get at the actual text value of each selected item within the loop, use: Listbox1.ItemData(SelItem)
And add it to the second listbox using something like: Listbox2.Additem (Listbox1.ItemData(SelItem))
Thats the basics.. Check out Access help for the specifics of each.
Cheers, A
Edited by Bunce
|
|
There have been many, many posts made throughout the world...
This was one of them.
|
 |
ziwez0
Groupie
Joined: 15 July 2002
Location: United Kingdom
Status: Offline
Points: 144
|
Post Options
Thanks(0)
Quote Reply
Posted: 16 October 2003 at 5:27am |
Andrew, cheers for the help ive just punched in the code you gave me...
-----Listbox1----------
Private Sub Listbox1_Click() Listbox1.ItemSelected For Each SelItem In Listbox1.ItemSelected Listbox1.ItemData (SelItem) End Sub
-----Listbox2-------
Private Sub Listbox2_AfterUpdate() Listbox2.AddItem (Listbox1.ItemData(SelItem)) End Sub
And it dont work...?
where does the button come invloved?
Cheers buddy
|
|
If anything takes long to do its worth doing.
|
 |
Bunce
Senior Member
Joined: 10 April 2002
Location: Australia
Status: Offline
Points: 846
|
Post Options
Thanks(0)
Quote Reply
Posted: 16 October 2003 at 5:36am |
The code I gave you won't work as it is. You'll need to look in Access help to get the specifics. It was just a starter.
Where does the button come involved? You said initially that you wanted to copy the selected items when clicking a button. Therefore you need create a button on the form, and in the _onclick() event, place all your code in there.
It will basically look something like this, however there are other things you must set up also (see help) :
Private Sub Button1_OnClick()
For Each SelItem In Listbox1.ItemSelected Listbox2.AddItem (Listbox1.ItemData(SelItem)) Next
End Sub |
I strongly suggest you look at some of the examples in Access help, that way you will learn some of the syntax so you can do these types of things for yourself in the future.
Good luck!
|
|
There have been many, many posts made throughout the world...
This was one of them.
|
 |