If Statement

G

Guest

Hi,

I need a report to print for any other type than those listed in the
following statement and I'm getting a Type Mismatch error.

If Me.Parent!TypeCombo = Not "Red" Or Not "Blue" Or Not "Green" Then
DoCmd.OpenReport "rReportRegular", , , "JobNumber=" & Me.JobNumber

Hoping someone will give the correct code.
Thanks in advance,
Pam
 
B

BruceM

Something like:

If Me.Parent.TypeCombo <> "Red" And Me.Parent.TypeCombo <> "Blue" _
And Me.Parent.TypeCombo <> "Green" Then
DoCmd.OpenReport "rReportRegular", , , "JobNumber=" & Me.JobNumber
End If

I think you will find you want to use And rather than Or for a "does not
equal" situation. If it is not red OR not blue then it doesn't exclude
either red or blue.

Select Case may be tidier in some cases:

Select Case Me.Parent.TypeCombo
Case "Red","Blue","Green"
' do nothing
Case Else
DoCmd.OpenReport "rReportRegular", , , "JobNumber=" & Me.JobNumber
End Select

You don't actually need the ' do nothing line. There may be another way to
do this, but I can't think what it would be in the *absence* of one of
several conditions.
 
D

Douglas J. Steele

You can't shortcircuit like that: you have to repeat the reference to the
control each time:

If Me.Parent!TypeCombo <> "Red" And _
Me.Parent!TypeCombo <> "Blue" And_
Me.Parent!TypeCombo <> "Green" Then
DoCmd.OpenReport "rReportRegular", , , _
"JobNumber=" & Me.JobNumber
End If

Note the other changes I made. You use <> to represent not equal to. Using
Or in this situation doesn't make sense: ALL selections would pass the
criteria, since any selection can only have one value, and therefore can, at
most, be equal to only one of the three choices.
 
G

Guest

Thanks Bruce and Doug for the prompt replies. Works like a charm!! I
thought it should have been "<>" and originally tried it, but not exactly as
you have it and received an error message. And then there's the and/or
factor...

Thanks again for all your help - greatly appreciated!
Pam
 

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