View Full Version : A COMBO of a problem


ian_ok
05-22-2001, 03:45 AM
I've got a combo box which displays names and addresses, yet when you decide on which one to pick it only displays the surname, how can I get it to display the rest of the data that is originally shown in the drop down.

Ian

Pat Hartman
05-22-2001, 05:53 AM
When the combobox is "at rest" it only shows the first visible column. You can get around that in either of two ways. Change the combo's recorsource query to add a field that concatinates all the data you want to show in the combo and don't include the base columns. So:
Select keyfld, LastName & ", " & FirstName & " - " & WorkPhone AS ContactInfo
From YourTable;

The other way is to add unbound text boxes to the form and in the AfterUpdate event of the combobox, populate the unbound text boxes.

Me.txtFirstName = Me.txtCombo.Column(2)
Me.txtWorkPhone = Me.txtCombo.Column(3)

ian_ok
05-22-2001, 07:03 AM
Thanks once again Pat...but!

One small problem I've used your unbound method and I get ERROR message Microsoft Access can't find the macro 'Me'

Any help?

Ian

ian_ok
05-22-2001, 07:13 AM
OK....I didn't know you meant code!!!

This is what I've done, but I get a compiler error...ANY HELP?

Private Sub offered_AfterUpdate()
Me.txt10 = Me.txtCombo.Column2
End Sub

Ian

PS It's also my first bit of code so be kind!!!


[This message has been edited by ian_ok (edited 05-22-2001).]

chrisk
05-22-2001, 07:36 AM
The column numbers are an array, so you need the brackets round the 2, ie

Private Sub offered_AfterUpdate()
Me.txt10 = Me.txtCombo.Column(2)
End Sub

Chris.

ian_ok
05-22-2001, 07:49 AM
Thjanks Chris.....but!

I still get a compiler error

The private sub line gets a yellow arrow and the txtCombo is highlighted blue!

I've tried to change the word Combo to what the combo is called ie offered, but I still get the error>

Private Sub offered_AfterUpdate()
Me.txt10 = Me.txtCombo.Column(2)
End Sub

Any more help for a non coder

Ian

LeslieB
05-22-2001, 08:09 AM
try this ...

instead of me use the name of the form

Pat Hartman
05-22-2001, 10:20 AM
I forgot to tell you that the combo's column array is zero based. The first column is referenced as (0), the second as (1), the third as (2), etc. Make sure the column number you are using is not past the end of the array.

PS, don't forget any hidden columns. It is best to look at the query to figure out the column numbers.

[This message has been edited by Pat Hartman (edited 05-22-2001).]

Rich
05-22-2001, 11:35 AM
Open the property sheet for the form in design view, click on the combo box, click the "Other" tab on the property sheet the name of your combo box will be there copy and paste it after Me. add the column reference after.
HTH

ian_ok
05-23-2001, 06:36 AM
Still not working, have tried Rich's method, the error doesn't appear but neither does the info in the text box!!

Below is my code...
The combo box is called 'offered1 and the text box is called 'test' and there is data in column 3 to copy over

Private Sub offered_AfterUpdate()
Me.txttest = Me.txtoffered.Column(3)
End Sub

What is wrong with the code?

Ian

charityg
05-23-2001, 06:53 AM
Like Pat said, the array is zero based, so use
Private Sub offered_AfterUpdate()
Me.txttest = Me.txtoffered.Column(2)
End Sub

ian_ok
05-23-2001, 07:08 AM
It works when I do the code given below, BUT it also updates the next offer for that person ie it adds the info in the next text box, any suggestions?

Remember this is a subform, so after you start to enter the first offer the offer under it becomes 'live'...I think this is what i need to stop?

It also changes each of the text box data to which ever offer person you choose, instead of being kept different for each offer


Private Sub offered_AfterUpdate()
Me.test = Me.offered.Column(3)
End Sub

[This message has been edited by ian_ok (edited 05-23-2001).]

charityg
05-23-2001, 08:56 AM
Is your combobox a bound control? If it isn't, and your text boxes aren't bound, then none of the information is specific to the current record. The easiest way to fix this would be to bind the combo box to a field in the form's underlying datasource where you want to store the information that the combobox is selecting.