Fill text boxes on form based on combo box selection

George82

Registered User.
Local time
Tomorrow, 00:45
Joined
Dec 8, 2011
Messages
15
[FONT=&quot]I have a combo box on a form that has the model of the product.[/FONT]
[FONT=&quot]I want when I select the type of model on the combo box to fill automatically the text boxes on my form with the quantities of the accessories for this model.[/FONT]
[FONT=&quot]For example… I select model A on the combo box I want to be displayed in the text boxes below that battery is 1, cables are 2..etc[/FONT]
[FONT=&quot]
I have so far a table that combo box uses with the type model and the accessories.[/FONT]

[FONT=&quot]
[/FONT]

[FONT=&quot]Build like this: [/FONT]
[FONT=&quot]Model[/FONT][FONT=&quot] .. CABLES[/FONT][FONT=&quot] ..BATERRIES [/FONT][FONT=&quot]..MANUAL[/FONT]
[FONT=&quot]...A[/FONT][FONT=&quot] ..............2[/FONT][FONT=&quot] .................1[/FONT][FONT=&quot] ....................1[/FONT]
[FONT=&quot]...B[/FONT][FONT=&quot] ..............1[/FONT][FONT=&quot] .................1[/FONT][FONT=&quot] ....................1[/FONT]
[FONT=&quot]...C[/FONT][FONT=&quot] ..............1[/FONT][FONT=&quot] .................0[/FONT][FONT=&quot] ....................1[/FONT]


[FONT=&quot]And in the after update event of the combo box I have entered:[/FONT]

[FONT=&quot] Private Sub MODEL_AfterUpdate()[/FONT]
[FONT=&quot]Me.cables = Me!MODEL.Column(1)[/FONT]
[FONT=&quot]Me.batteries = Me!MODEL.Column(2)[/FONT]
[FONT=&quot] Me.manual = Me!MODEL.Column(3)[/FONT]
[FONT=&quot] End Sub[/FONT]

[FONT=&quot]But nothing happens…[/FONT]
[FONT=&quot]I would most appreciate some help[/FONT]
 
Hello ther, I believe you are just missing some small details to your code.. try the following it should work..
Code:
Private Sub MODEL_AfterUpdate()
    Me.cables.Value = Me!MODEL.Column(1,Me!MODEL.ItemsSelected)
    Me.batteries.Value = Me!MODEL.Column(2,Me!MODEL.ItemsSelected)
    Me.manual.Value = Me!MODEL.Column(3,Me!MODEL.ItemsSelected)
End Sub
 
[FONT=&quot]Thank you for your instant reply ![/FONT]
[FONT=&quot]Unfortunately I still don’t get anything on the text boxes…[/FONT]
[FONT=&quot]What parameter could I be missing? [/FONT]
 
Give me the RowSource of the ComboBox and its ColumnCount. Are you getting any error while executing? if so provide the error too..
 
I don’t get any errors while executing..

The RowSource of the combobox is:

SELECT MODEL.MODEL, MODEL.TYPE FROM MODEL WHERE (((MODEL.TYPE)=[Forms]![STEPS]![TERM TYPE]));

I have set it to take each values according to the selection of another combobox (Term type).

I select term type then model and then it should display the number of accessories in the text boxes.
I am kind of new to the hall access vba programming so where can I find the columncount?
Is it the bound column that is set to 1?

Again thank you for your interest!
 
Well based on your query it is returning only two Columns CHECK YOUR QUERY to return three columns... so I guess the query should be something like..(higlighted in RED)
Code:
SELECT MODEL.MODEL, MODEL.TYPE[COLOR=Red], MODEL.MANUAL [/COLOR]
FROM MODEL WHERE (((MODEL.TYPE)=[Forms]![STEPS]![TERM TYPE][COLOR=Red].Value[/COLOR]));
and you are not getting any result because I believ the column count is set to 1, so it is returning NULL for colums 2 and 3 which is placed on the textfield but not visible..

Also note that the Column propertt is 0-based so Column 0 is the first column and Column3 means the 4th column.
so based on that the code will be.. something like.. (highlighted in RED)
Code:
Private Sub MODEL_AfterUpdate()
    Me.cables.Value = Me!MODEL.Column([COLOR=Red]0[/COLOR],Me!MODEL.ItemsSelected)
    Me.batteries.Value = Me!MODEL.Column([COLOR=Red]1[/COLOR],Me!MODEL.ItemsSelected)
    Me.manual.Value = Me!MODEL.Column([COLOR=Red]2[/COLOR],Me!MODEL.ItemsSelected)
End Sub
The columnCount will be available in Format tab of the ComboBox.. see the attachmetn for details.

Post back if still in trouble.
 

Attachments

  • Look.jpg
    Look.jpg
    80.2 KB · Views: 527
Last edited:
You are welcome.. So the Text fields are showing the values now, I believe. Use Debug.Print to see if it is printing the values in any part where you think is not working, that will help a lot.
 

Users who are viewing this thread

Back
Top Bottom