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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select FieldName Based On Feild Value 1

Status
Not open for further replies.

SwingXH

Technical User
Jun 15, 2004
97
US
Is there a way to get certain field name based on the field value using a query?
For example, I have a form based on the table below

ID Name Age Height
1 John 34 5.6
2 Ken 55 6.6

I want to make a combo box, when Height>5.5, Height becomes rowsource of the combo box list. If Height>5.5 and Age>50, then both Age and Height become the rowsource of the combo box list.

Hope this is clear.
Many thanks in advance!
SwingXH
 
You can set the cbo.ComboField.rowsource dynamically.

me.cbo.ComboField.rowsource = "SELECT * FROM X WHERE Y..."

The key is when do you need this set. On the Form Load, as a default, then on the change event of one of other fields you mentioned?

htwh

Steve Medvid
"IT Consultant & Web Master"

Chester County, PA Residents
Please Show Your Support...
 
for now, as a start, I'll make it in the form load event only and only for the current record. But later I wish when I switch to different record on this form, combo box row source will change dynamically.

When I use the code above you mentioned, got an error "Method or data member not found" with "ComboField" highlighted.
BTW, I am using Access 2000.

Thanks,
SwingXH
 
ComboField is your field name for the combo-box that you are attempting to modify. Also, I think there is an On Current Event on the form that you may be able to use? htwh,,

Steve Medvid
"IT Consultant & Web Master"

Chester County, PA Residents
Please Show Your Support...
 
Sorry, I do not get it. My combo box is not bound to any table. What is the field name for the combo box? Can you give me a simple example?
Thank you very much!
SwingXH
 
Check the properties of your ComboBox. Every object on the form has a name associated with it. The default name is something like Combo1, where 1 is incremented for each occurance of another Combobox.

A better practice is to always rename objects and change the default name. For example, if Combo1 represent an Employee ID Combobox, then I would rename the object cbo_Employee_ID.

So, find out the name of the Combobox object that you are attempting to change the record source of.

Good luck.


Steve Medvid
"IT Consultant & Web Master"

Chester County, PA Residents
Please Show Your Support...
 
Yes, then what is cbo in the codes you gave me?
me.cbo.ComboField.rowsource = "SELECT * FROM X WHERE Y..."

For the example table I have in previous posts,
how to write the query to get field name "Height" for height>5.5?

Thanks a lot,
SwingXH
 
Thanks.
For record 1, When I use
Me.Combo30.RowSource = "SELECT * FROM Employees WHERE Height>5.5"
it gave me 1, which is the ID.

If i use
"SELECT Height FROM Employees WHERE Height>5.5"
it gave me 5.6.

However, what i want is the field name, I want "Height" when Height>5.5.
How to write the query?
Thanks,
SwingXH
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top