Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

set combobox based on value in a textbox

Status
Not open for further replies.

Zorro1265

Technical User
Nov 14, 2000
181
0
0
US
I have a textbox that has a persons age. Based on that value I want the form to modify the value in an unbound combobox on the same form. I am trying to refer to the value in the first (hidden) column of the combobox. I keep getting an error object required. Any help would be appreciated greatly!

Heres what I have.

If Me.PtAge.Value < 34 Then
Me.age.Column(0) = 1
ElseIf Me.PtAge.Value > 34 Then
Me.age.Column(0) = 2
ElseIf Me.PtAge.Value > 39 Then
Me.age.Column(0) = 3
ElseIf Me.PtAge.Value > 44 Then
Me.age.Column(0) = 4
ElseIf Me.PtAge.Value > 49 Then
Me.age.Column(0) = 5
ElseIf Me.PtAge.Value > 54 Then
Me.age.Column(0) = 6
ElseIf Me.PtAge.Value > 59 Then
Me.age.Column(0) = 7
ElseIf Me.PtAge.Value > 64 Then
Me.age.Column(0) = 8
ElseIf Me.PtAge.Value > 70 Then
Me.age.Column(0) = 9
End If

The &quot;me.age....&quot; is where the error is flagged.

Thanks Zorro
 
Zorro:

Does the user enter his/her age in the text box? And, is this field part of a table.

If there seems to be only 1 value assigned to an age, why pass it to an unbound combo box, which suggests that a list of items is possible?

Jim &quot;Get it right the first time, that's the main thing...&quot; [wavey]
 
Hiya,

You're probably referring to the wrong column.

Have you experimented with
Me.age.Column(1)
instead of
Me.age.Column(0) ?

If you have Option Explicit set in your forms, then the fact that age is lower case might indicate that it should be Me!Age.column(0) (! instead of . )

Bear with me - I have little info.

Regards,

Darrylle






&quot;Never argue with an idiot, he'll bring you down to his level - then beat you with experience.&quot;
 
The age is entered as one component of a formula. Some of the components are subjective so they cannot be set by code but rather by user input. The values are read from the non-subjective fields and I would like the to set the combo's to the appropriate values. Once this is done the dubjective items can be picked and a the calculation is done based on several combo boxes. I have that working its just getting the boxes to set themselved that is hanging up. The combo box items are not stored in a table but the result of the calculation will be stored.

I tried changing to me!age and I just get a different set of errors.

Can I set the value of a combobox via VBA on load this way?
me.age.column(0)=1
I want the value of the first column in the combo to be 1. Zorro
 
Hiya,

I know that you want info from a combo, and that you have said that fields are 'hidden' - you're not using a query for the combo and clicking 'don't show' in the query are you?

If so, the combo won't have the value. If you don't want to show a value in the combo, then you make it zero width.

Sorry if I offend - just looking at possibilities.

Regards,

Darrylle

&quot;Never argue with an idiot, he'll bring you down to his level - then beat you with experience.&quot;
 
The values are brought in with a query and I am making it zero width, I even tried making the hidden column wider to see it and that was a dud. I figure if I could set the combo with a line of code on the load event or something that may give me a clue on how to do it with my if then.

I appreciate any ideas and I don't offend easily, just don't talk about my mother! (haha) Zorro
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top