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

how to set value in one control box by the result in another?

Status
Not open for further replies.

Gustavson

Technical User
Nov 2, 2001
105
US
I'm using access97. In a form I have three combo boxes.

Chemical: boric acid
Unit Measure:gallons
Pysical State: liquid

Is there a way to get the Physical State control box to automatically display liquid if gallons is inserted into the Unit Measure control box?

Hope this is enough info...
Thanx
Gustavson
 
Gustavson:

In the After Update event of the measure combo put this code:

If cboMeasure = "Gallons" then
cboState = "Liquid"
End If

You will need to use the appropriate names for the combos If the bound column of the measure combo is numeric, change the test to the number for Gallons. Also, if the bound column for the state combo is numeric change that also.

Hope this helps. Larry De Laruelle
ldelaruelle@familychildrenscenter.org

 
Larry - okay that worked great. Now is there a way to put an If else statement incase the value of Unit Measure is in grams and physical state is solid. Here's the code that works so far:

Private Sub U_M_combo_AfterUpdate()
If Me.[U/M combo] = "gal" Then
Me.[Physical State combo] = "l"
End If
End Sub

Thanx
Gustavson

 
Larry - Bye the way, there are multiple choices in the Unit Measure combo box - Gallons, grams, Liters, Kilograms, etc..
So, they are usually either a liquid, solid, or gas. For example Gallons is usually always a liquid and grams is usually always a solid. Anyways, I tried using the Else statement but it only allows me to use one more value. I need to use some kind of if else statement here because I have more than two values...

Thanx
Gustavson
 
Okay - here's my solution:

Private Sub U_M_combo_AfterUpdate()
If Me.[U/M combo] = "gal" Then
Me.[Physical State combo] = "l"
Else
If Me.[U/M combo] = "g" Then
Me.[Physical State combo] = "s"
Else
Me.[Physical State combo] = "g"
End If
End If
End Sub

Gustavson
 
Gustavson:

There are two ways to approach this -- Use an If, Then Else If conditional or use a Select Case statement. Given your conditions, a Select Case may be most appropriate.

Select Case U_M_combo
Case "Gal"
[Physical State combo] = "i"
Case "g"
[Physical State combo] = "s"

.
.
Case Else
[Physical State combo] = whatever the last choice is.
End Select

If necessary, you can use an If, Then, Else statement within the Case statement.

Is this what you need?
Larry De Laruelle
ldelaruelle@familychildrenscenter.org

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top