open form ubder conditions

E

emma

Hi,

Ihave two forms, called Form1 and Form2.
Form1 contains Command1
Form2 contains combobox1 and combobox2

I want to open form2 using command1_click.
After opening me.combobox must be "3" and
me.combobox2 must be "5'.
The numbers "3"' and "5"are variabeles generated in form1.


Private Sub Command1_Click()
DoCmd.OpenForm ("form2")
' with condition:
' WHERE me.combobox LIKE "3" AND me.combobox2 LIKE "5'
End Sub



Thanks,

Emma
 
K

Klatuu

Your post is confusing in that I don't see anything conditional about it. If
they will always be 3 and 5, then in the Load event of form 2

With Me
.combobox1 = 3
.combobox2 = 5
End With

If that is not what you want, please clarify your question and we can help.
 
A

Albert D. Kallal

I want to open form2 using command1_click.
After opening me.combobox must be "3" and
me.combobox2 must be "5'.
The numbers "3"' and "5"are variabeles generated in form1.


docmd.OpenForm "form2"
forms!Form2.combobox = 3
forms!form2.combobox2 = 5

You don't mention what the actual vars are, but you would replace the 3 and
5 with the variable names in the above code.....
 
L

Linq Adams via AccessMonster.com

Your code with the "Where"is actually looking for a record that already exits
where the comboboxes are already set to 3 and 5, not setting the values of
the comboboxes. If Dave's guess is incorrect, and the 3 and 5 were just
examples of what the two variables may be, something like this will work,
remembering that the variable values must be available to your Command1 sub:


In your Form1

Private Sub Command1_Click()
DoCmd.OpenForm "Form2", , , , , , Variable1 & ";" & Variable2
End Sub

In your Form2

Private Sub Form_Open(Cancel As Integer)
If Not IsNull(Me.OpenArgs) Then
VarValues = Split(Me.OpenArgs, ";")
Me.ComboBox1 = VarValues(0)
Me.ComboBox2 = VarValues(1)
End If
End Sub
 
K

Klatuu

I considered including almost exactly what you propose, but didn't only
because the OP did not really make it clear.
 

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