Open a Specific Form By Variable Contol in Another Form

mstorer

Registered User.
Local time
Today, 18:37
Joined
Nov 30, 2001
Messages
95
I want to open 1 of 2 forms depending on the value of a control in another. For example:

If [Form1].[Premium]>0 Open [Form2]
If [Form1].[Premium]=0 Open [Form3]

I don't see how to do this in a Macro and my VB skills are...well I don't have any. Thanks in advance for any assistance.
 
Thanks for the response Chris. I don't think I was very clear. I know how to open forms based on various criteria. My goal is to have the user click a command button and open a form. Which form opens depends on the value of a control in the current form. I suppose my question is: Where does the filter go and what does it look like? Is this an action that requires VB code? Perhaps I am missing something quite obvious.
 
If Me!Premium > 0 Then
Docmd.OpenForm "Form2"
end if

If Me!Premium = 0 Then
Docmd.OpenForm "Form2"
end if
 
Thanks for your help. I tried the code changing it to match my actual field and form names. Unfortunately, I received a syntax error message. I may need to re-evaluate the way the users move to the next screens. Thanks again.
 
What syntax error did you receive? Was a particular piece of the code highlighted? Are you inside the Click event for your button (between Private Sub Command4_Click... and End Sub, for example).
 
Thanks for sticking with this everyone. The error reads as follows: "Compile Error: Syntax Error"
Following is the code that I have entered inside the click event:
Private Sub Next_Click()
IIf Me!Liability Premium > 0 Then
DoCmd.OpenForm "Liability Subline"
End If
IIf Me!Liability Premium = 0 Then
DoCmd.OpenForm "Page 2 AQS "
End If

End Sub

The following line is highlighted yellow:
Private Sub Next_Click()

Both of the lines beginning with "IIf" are in red type. Thanks again for your insights.
 
That would be your problem. The correct syntax is:

Private Sub Next_Click()
If Me!Liability Premium > 0 Then
DoCmd.OpenForm "Liability Subline"
End If

If Me!Liability Premium = 0 Then
DoCmd.OpenForm "Page 2 AQS "
End If
End Sub


Get rid of the IIF and replace with IF

IIF is only used in the formulas in Queries, control sources, or Macro conditions.

BL
hth
 
That did the trick. Thanks everyone. Although I'm sure it was a elementary problem, your help definately got me through a big road block. Thanks Again.
 
No problem. We all started somewhere, and this Forum is for asking questions, not showing off how few questions you have to answer. Don't worry about it.
biggrin.gif
 

Users who are viewing this thread

Back
Top Bottom