Open form based on combo box selection

stocmamu

New member
Local time
Today, 12:56
Joined
Jan 14, 2010
Messages
3
I am using Access 2007 and have a data entry form and on it is a combo box that I would like to be used to determine what form would be opened next after a button is pushed on the form. So the user makes a selection from the combo box, then, depending on what was selected, a new form will be opened after a button is pushed on the first form. If I use a macro, what is the specific language I should use in the "Where Condition" in the OpenForm action?
 
The wherecondition does not determine which form to open, just which record(s) will be displayed on that form. If you want to open different forms, I'd use code. If you want to stick with a macro, you'd have to test the value of the combo in the Condition area.
 
I had a feeling I would need to use VBA. Anyone have the code to do this? Unfortuantely for me I am a VBA novice and if I cant write a macro for it I cant get it into the database.

Thanks,
 
Like I said, you can do it with a macro, you just have to use a Condition. In code, this type of thing:

Code:
Dim strForm As String

If Me.ComboName = "A" Then
  strForm = "FormA"
ElseIF Me.ComboName = "B" Then
  strForm = "FormB"
Else
  strForm = "FormC"
End If

DoCmd.OpenForm strForm
 
if your combo data source come from a table, I suggested you add a field in that table that store "form name", so the task is very simple:

docmd.openform me.myformnamecombo ,.....
 
Like I said, you can do it with a macro, you just have to use a Condition. In code, this type of thing:

Code:
Dim strForm As String

If Me.ComboName = "A" Then
  strForm = "FormA"
ElseIF Me.ComboName = "B" Then
  strForm = "FormB"
Else
  strForm = "FormC"
End If

DoCmd.OpenForm strForm



How can I let form to open specific record like ="[customerID]=" & [customerID]? Also in this code. So, i need to open specific record, but depending on value in this record i must to open different forms. This sample code works fine for me, only one problem is what i don't know how to open specific record. I don't know a syntax's.
P.S. Sorry, i am new in this forum. And i am from Latvia. :)
 
The red highlighted portion is what you will need to add;
Code:
Dim strForm As String

If Me.ComboName = "A" Then
  strForm = "FormA"
ElseIF Me.ComboName = "B" Then
  strForm = "FormB"
Else
  strForm = "FormC"
End If

DoCmd.[URL="http://msdn.microsoft.com/en-us/library/office/bb238021%28v=office.12%29.aspx"]OpenForm[/URL] strForm[COLOR="Red"][B], , ,"customerID= " & Me.customerID[/B][/COLOR]

Note; that customerID must be a field that resides on your current form.
 
Tnx a LOT! It works! Finaly! Yee... When You will be in Riga - bear from me! :)
 
Should I ever visit Riga I will look forward to sharing a

beer.jpg


but not a

bears-2.jpg


big_grin_smiley_face_sticker-p217746367994550126qjcl_400.jpg
 

Users who are viewing this thread

Back
Top Bottom