One form or another depending on criteria

T

Tara

I have a form that is used to collect demographic information for
presentation participants. Depending on certain criteria on the form, I then
need to open one of 2 other forms. What is happening though is that BOTH
forms open, with frmTest on top. Here's the code I currently have:

Dim stLinkCriteria As String

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

stLinkCriteria = "[ParticipantID]=" & Me![AttendID]

If Forms!frmParticipants!EducationalLvl = 1 Or 2 Then
DoCmd.OpenForm "frmTest4th5th", , , stLinkCriteria

If Forms!frmParticipants!EducationalLvl = 3 Or 4 Or 5 Or 6 Or 7 Then
DoCmd.OpenForm "frmTest", , , stLinkCriteria

End If
End If

Any help is appreciated!
 
R

RonaldoOneNil

If Forms!frmParticipants!EducationalLvl < 3 Then
DoCmd.OpenForm "frmTest4th5th", , , stLinkCriteria
End If

If Forms!frmParticipants!EducationalLvl > 2 Then
DoCmd.OpenForm "frmTest", , , stLinkCriteria
End if
 
T

Tara

Perfect! I was wondering about all those Or's I had in there...

Thanks!

RonaldoOneNil said:
If Forms!frmParticipants!EducationalLvl < 3 Then
DoCmd.OpenForm "frmTest4th5th", , , stLinkCriteria
End If

If Forms!frmParticipants!EducationalLvl > 2 Then
DoCmd.OpenForm "frmTest", , , stLinkCriteria
End if

Tara said:
I have a form that is used to collect demographic information for
presentation participants. Depending on certain criteria on the form, I then
need to open one of 2 other forms. What is happening though is that BOTH
forms open, with frmTest on top. Here's the code I currently have:

Dim stLinkCriteria As String

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

stLinkCriteria = "[ParticipantID]=" & Me![AttendID]

If Forms!frmParticipants!EducationalLvl = 1 Or 2 Then
DoCmd.OpenForm "frmTest4th5th", , , stLinkCriteria

If Forms!frmParticipants!EducationalLvl = 3 Or 4 Or 5 Or 6 Or 7 Then
DoCmd.OpenForm "frmTest", , , stLinkCriteria

End If
End If

Any help is appreciated!
 
J

John W. Vinson

Perfect! I was wondering about all those Or's I had in there...

They weren't working because of the way OR works.

It *looks* like the English language conjunction, but it isn't! Instead it's
an operator in the language of Boolean algebra, just as + and - are operators
in the language of arithmatic.

X OR Y

returns TRUE if X is true, or Y is true, or both are true. It returns False if
neither is true.

In your expression

If Forms!frmParticipants!EducationalLvl = 3 Or 4 Or 5 Or 6 Or 7 Then

you are comparing the expression

Forms!frmParticipants!EducationalLvl = 3

(which might or might not be true, depending on what's in EducationLvl) with
the expression

3

which is ALWAYS TRUE, since to Access, 0 is False, anything else is True.

Then you're comparing that expression - True, actually seen as -1 - to the
expression

4

which is also True... and so on and so on.

If you do need to make several comparisons, you need to compare *expressions*,
not values:

IF Forms!frmParticipants!EducationalLvl = 3 OR _
Forms!frmParticipants!EducationalLvl = 4 OR _
Forms!frmParticipants!EducationalLvl = 5 OR _
Forms!frmParticipants!EducationalLvl = 6 OR _
Forms!frmParticipants!EducationalLvl = 7
 

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