auto-input text bx depending on 2 drops

  • Thread starter Dispatcher Scott
  • Start date
D

Dispatcher Scott

Insane. that's where I'm headed...

I have a form where I created 2 drop down boxes. When I created the drop
downs, I inputted the info manually (rather than use info from a table). I
have a text box that is dependant on what 2 items are selected from the
drop-downs.
i.e:
drop 1 = "2"
drop 2= "low"
txt box = 4.4
the drop down values are:
drop 1 is numbered 1-9
drop 2 is (Low, Medium or High)

so the values combined will determine what the value in the txt box is.

What is the easiest way for me to do this? I am a VB code idiot, I've
searched on the internet for some resources, but don't really know how to
word my search.

I have ordered a book from amazon.com on VB coding, in hopes to learn a
little more, but I'm being pushed for time as this is a work project.

any help would be appreciated. Thanks in advance.
 
K

KARL DEWEY

I either missed something or you omitted what is suppose to appear in the
text box.

How do you get 4.4 by selecting '2' and 'Low' with the 2 drop down boxes?
 
D

Dispatcher Scott

Sorry about that, that seems to be my fault.

the values in the txt box are dependant on th combined values of the 2
drop-downs:

here is a short list of possible combinations:

drop 1 | drop 2 | txt bx value
-----------------------------------
1 | Low | 3.0
1 | Medium | 4.0
1 | Heavy | 4.4
2 | Low | 2.6
2 | Medium | 3.8
2 | Heavy | 5.1
etc...

the values for each combination are set depending on the combination of the
two.
 
M

Mr. B

Dispatcher Scott,

I would suggest that you design a table just exactly like the design you
posted here having the first set of values for first combo box in one field,
the second set of values for the second combo box in the second field and the
appropriate value that would then be in the text box in the third column.

Then you can populate your first combo box with a query that returns only
the unique values from the first field. Populate your second combo box with
a query that returns on the uniqe values from the second field.

Then you can use a do a simple query in code that will return the
appripriate value from the third column where the first field and the second
field match the values selected in the two drowdown lists.

Please understand that the variables that I have declared can and should be
changed to reflect the data type you are using and naming conventions that
you would understand when seeing them.

In the AfterUpdate event of both combo boxes, you can use code like the
untested code below:

'start of Code
'declaring this variable as Byte assumes that the field is also a number
declared
'as Byte

Dim bytValue1 as Byte
Dim strValue2 as String
Dim strTxtBxVal as String
Dim strSql as String
'The next declaration assumes that in the VBA code window
'(select Tools/References) you have set a reference to the
'Microsoft DAO 3.6 Object Library
Dim rs as DAO.Recordset

If Not Isnull(Me.NameOfComboBox1) _
And Not Isnull(Me.NameOfComboBox2) Then
bytValue1 = Me.NameOfComboBox1
strValue2 = Me.NameOfComboBox2
strSql = "SELECE ThirdFieldName FROM YourTableName " _
& "WHERE NameOfFieldOne = " & bytValue1 & " " _
& "NameOfFieldTwo = '" & strValue2 & "';"
set rs = Currentdb.OpenRecordSet(strsql)
Me.NameOfYourTextBox = rs.Field("ThirdFieldName")
rs.close
rs.close
EndIf
'end of code

HTH
Mr. B
(askdoctoraccess dot com)
 
K

KARL DEWEY

Using Mr. B suggestion of translation table you can do it in a query by
placing both tables in the design view grid. Pull down the [Drop 1] and
[Drop 2] fields from the translation table and use drop down 1 as criteria on
first and drop down 2 on the second. Pull down [txt bx value] field into the
grid.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top