Open a form based on 2 fields from 2 combo boxes

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form with 2 combo boxs where i enter, for example, and ID and a name. Both Combo boxes are unbound

This is supposed to open a new form based on the criteria i have put on my combo boxs.

Can Access do it for me or i have to go to VBA

On VBA, how can i do it ?

Thanks for your help
 
-----Original Message-----
I have a form with 2 combo boxs where i enter, for
example, and ID and a name. Both Combo boxes are unbound.
This is supposed to open a new form based on the criteria i have put on my combo boxs.

Can Access do it for me or i have to go to VBA?

On VBA, how can i do it ?

Thanks for your help
.
The way to do this is by adding a commnd button and
puttig the following code in the On Click event

Dim stLinkCriteria As String

Dim stDocName As String
stLinkCriteria = "[Value1]=" & me.cboComboBox1 & " AND "_
"[Value2] = " & me.cboComboBox2
DoCmd.OpenReport FormName, , , stLinkCriteria
There are a couple of conciderations to think about.

1. Both of the combo boxes need to be populated by the
user. You can check for that using If Then Else statements
before running the code.

2. If the data in the combo box is a string you must use
quotes around the code like this

stLinkCriteria = "[Value1]= '" & me.cboComboBox1 & "'" _
& " AND " & "[Value2] = '" & me.cboComboBox2 & "'"

3. If the data in the combo box is a date you need to
surround the value with #'s like this

stLinkCriteria = "[Value1]= #" & me.cboComboBox1 & "#" _
& " AND " & "[Value2] = #" & me.cboComboBox2 & "#"
 
I am very greatfull for your help and support

However i forgot to mention 1 thing: My apologie

The Value1 is my main Value and the Value2 "must show only" in the combo bo
the values under the value 1.

For instances

Value1 Value
222 12
222 34
444 123
444 111

i have a query where are both values " QRYValues
Value1 ascending and Value2 Ascendin

cboComboBox1 is based on ROW Source
SELECT DISTINCTROW QRYValues.Value1 FROM QRYValues

on cboComboBox2 how do i have to do, just to have the values2 from the value i pu
in cboComboBox1 as i mentioned on my example ( 1234 , 1111)

Once again, thanks for your kindly hel

Best regard

José Santo
 
Back
Top