Open form based on combo box selection (1 Viewer)

stocmamu

New member
Local time
Today, 01:28
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?
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 01:28
Joined
Aug 30, 2003
Messages
34,062
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.
 

stocmamu

New member
Local time
Today, 01:28
Joined
Jan 14, 2010
Messages
3
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,
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 01:28
Joined
Aug 30, 2003
Messages
34,062
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
 

ntanh72

New member
Local time
Today, 01:28
Joined
Nov 16, 2009
Messages
7
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 ,.....
 

oswee

New member
Local time
Today, 11:28
Joined
Jul 24, 2012
Messages
3
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. :)
 

John Big Booty

AWF VIP
Local time
Today, 18:28
Joined
Aug 29, 2005
Messages
8,263
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.
 

oswee

New member
Local time
Today, 11:28
Joined
Jul 24, 2012
Messages
3
Tnx a LOT! It works! Finaly! Yee... When You will be in Riga - bear from me! :)
 

John Big Booty

AWF VIP
Local time
Today, 18:28
Joined
Aug 29, 2005
Messages
8,263
Should I ever visit Riga I will look forward to sharing a



but not a



 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top Bottom