Print Page | Close Window

Anyone know much about access programming

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Database Discussion
Forum Description: Discussion and chat on database related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=6408
Printed Date: 30 March 2026 at 3:54am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Anyone know much about access programming
Posted By: ziwez0
Subject: Anyone know much about access programming
Date 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.



Replies:
Posted By: Bunce
Date 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.


Posted By: ziwez0
Date 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.


Posted By: Bunce
Date 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



-------------
There have been many, many posts made throughout the world...
This was one of them.


Posted By: Bunce
Date 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.


Posted By: Bunce
Date 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



-------------
There have been many, many posts made throughout the world...
This was one of them.


Posted By: ziwez0
Date 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.


Posted By: Bunce
Date 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.


Posted By: ziwez0
Date Posted: 16 October 2003 at 6:22am

Cheers for the help/ advice Andrew.

Have a look at this.....

Private Sub MyButton_Click()
    Dim nCounter As Long
    Dim sSource As String

    For nCounter = 0 To DateBox.ListCount - 1
        If DateBox.Selected(nCounter) = True Then
            sSource = sSource & DateBox.ItemData(nCounter) & ";"
        End If
    Next

    sSource = Left$(sSource,Len(sSource)-1)
    frmSelectedDate.RowSource = sSource
End Sub



-------------
If anything takes long to do its worth doing.


Posted By: Bunce
Date Posted: 16 October 2003 at 7:06am

So you went the other way and iterated through all the items and created a string containing the selelected items, then assigned it to the recordsource of the second listbox.

Cool!  Works OK?  You might need to refresh/requery the second listbox to actualy display the items on screen.

Good work!

A

 



-------------
There have been many, many posts made throughout the world...
This was one of them.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net