opening different forms based on field value

G

Guest

I have a continous sub-form in my db to display a list of projects. I also
have a command button next to the record so that users can view the details
for that record. The problem is that I need to display a different form based
on a couple of fields in the record. ex: If ConditionA=True, Then display
Form A. If CondiitonB=True, then display FormB, If ConditionA=True and
ConditionB=True, then Display FormAB, else display FormC. Assistance is
greatly appreciated. The code I have to this point is:
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmFormC"

stLinkCriteria = "[MEA_Name]=" & "'" & Me![MEA_Name] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
 
T

tina

If ConditionA And ConditionB Then
stDocName = "FormAB"
ElseIf ConditionA Then
stDocName = "FormA"
ElseIf ConditionB Then
stDocName = "FormB"
Else
MsgBox "No condition met. OpenForm action cancelled."
Exit Sub
End If

stLinkCriteria = <etc, etc>
DoCmd.OpenForm <etc, etc>

if the criteria for the open form action is contingent on which form is
being opened, then you need to set the value of the stLinkCriteria variable
in each section of the If statement, directly after the value of stDocName
is set.

hth
 
G

Guest

You have to do this in the correct order so you get the results you want.
For example, if you start with ConditionA = True, it will open formA whether
conditionB is True or False.

If ConditionA = True And ConditionB = True Then 'A and B are both True
strDocName = "FormAB"
ElseIf ConditionA = True Then 'A is True and B is False
strDocName = "FormA"
ElseIf ConditionB = True Then 'A is False and B is True
strDocName = "FormB"
Else
strDocName = "FormC" 'A and B are both False
End If

stLinkCriteria = "[MEA_Name]=" & "'" & Me![MEA_Name] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
 
G

Guest

You missed FormC. If ConditionA and ConditionB are both false, the OP wanted
to open FormC

tina said:
If ConditionA And ConditionB Then
stDocName = "FormAB"
ElseIf ConditionA Then
stDocName = "FormA"
ElseIf ConditionB Then
stDocName = "FormB"
Else
MsgBox "No condition met. OpenForm action cancelled."
Exit Sub
End If

stLinkCriteria = <etc, etc>
DoCmd.OpenForm <etc, etc>

if the criteria for the open form action is contingent on which form is
being opened, then you need to set the value of the stLinkCriteria variable
in each section of the If statement, directly after the value of stDocName
is set.

hth


J said:
I have a continous sub-form in my db to display a list of projects. I also
have a command button next to the record so that users can view the details
for that record. The problem is that I need to display a different form based
on a couple of fields in the record. ex: If ConditionA=True, Then display
Form A. If CondiitonB=True, then display FormB, If ConditionA=True and
ConditionB=True, then Display FormAB, else display FormC. Assistance is
greatly appreciated. The code I have to this point is:
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmFormC"

stLinkCriteria = "[MEA_Name]=" & "'" & Me![MEA_Name] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
 
T

tina

oops!

If ConditionA And ConditionB Then
stDocName = "FormAB"
ElseIf ConditionA Then
stDocName = "FormA"
ElseIf ConditionB Then
stDocName = "FormB"
Else
stDocName = "FormC"
End If

stLinkCriteria = <etc, etc>
DoCmd.OpenForm <etc, etc>

if the criteria for the open form action is contingent on which form is
being opened, then you need to set the value of the stLinkCriteria variable
in each section of the If statement, directly after the value of stDocName
is set.

hth
 

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

Similar Threads


Top