Report Header Event

  • Thread starter mattc66 via AccessMonster.com
  • Start date
M

mattc66 via AccessMonster.com

I have the below code on one of my reports. The first "IF" statement fails to
work if my me.Brand = Amerec. However if it's any of my other If ...me.Brands
below the IF..Me.QuoteExp will work fine.

Can anyone explain why?

Private Sub PageHeader0_Format(Cancel As Integer, FormatCount As Integer)

'The below IF only works if me.brand is NOT AMEREC..
If IsNull(Me.QuoteExp) Then
lblPriceQuote.Visible = False
ElseIf Me.QuoteExp > 0 Then
lblPriceQuote.Visible = True
End If

If Me.Brand = "AMEREC" Then
rptALogo.Visible = True
rptFLogo.Visible = False
rptHLogo.Visible = False
rptPLogo.Visible = False
rptSLogo.Visible = False

ElseIf Me.Brand = "FINNLEO" Then
rptFLogo.Visible = True
rptALogo.Visible = False
rptHLogo.Visible = False
rptPLogo.Visible = False
rptSLogo.Visible = False

ElseIf Me.Brand = "HELO" Then
rptFLogo.Visible = False
rptALogo.Visible = False
rptHLogo.Visible = True
rptPLogo.Visible = False
rptSLogo.Visible = False

ElseIf Me.Brand = "POLAR" Then
rptFLogo.Visible = False
rptALogo.Visible = False
rptHLogo.Visible = False
rptPLogo.Visible = True
rptSLogo.Visible = False

ElseIf Me.Brand = "OEM" Then
rptFLogo.Visible = False
rptALogo.Visible = False
rptHLogo.Visible = False
rptPLogo.Visible = False
rptSLogo.Visible = True

ElseIf Me.Brand = "MCCOY" Then
rptFLogo.Visible = False
rptALogo.Visible = False
rptHLogo.Visible = False
rptPLogo.Visible = False
rptSLogo.Visible = True

End If




End Sub
 
A

Allen Browne

Just before the End If, temporarily insert these lines:
Else
Debug.Print Me.Brand, Len(Me.Brand)
Stop

When it stops, examine what was printed to the immediate window (Ctrl+G). It
may be that there is a leading space or some other non-visible character
that is not matching.

(Hint: Always include an Else in every Select Case or multiple If block.)
 
J

John Spencer

In addition to Allen's sage advice, I would rewrite the code slightly
Private Sub PageHeader0_Format(Cancel As Integer, FormatCount As Integer)

'The below IF only works if me.brand is NOT AMEREC..
If IsNull(Me.QuoteExp) Then
lblPriceQuote.Visible = False
ElseIf Me.QuoteExp > 0 Then
lblPriceQuote.Visible = True
End If

'Set all logos to visible false
rptALogo.Visible = False
rptFLogo.Visible = False
rptHLogo.Visible = False
rptPLogo.Visible = False
rptSLogo.Visible = False

'Set one logo visible
Select Case Me.Brand
Case "AMEREC"
rptALogo.Visible = True
Case "FINNLEO"
rptFLogo.Visible = True
Case "HELO"
rptHLogo.Visible = True
Case "POLAR" Then
rptPLogo.Visible = True
Case "OEM" Then
rptSLogo.Visible = True
Case"MCCOY" Then
rptSLogo.Visible = True 'Note same as OEM so could be combined
with OEM case
Case Else
Msgbox "Unknown Brand" 'Or debug.Print statement or generic
logo
End Select
End Sub
--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..

Allen Browne said:
Just before the End If, temporarily insert these lines:
Else
Debug.Print Me.Brand, Len(Me.Brand)
Stop

When it stops, examine what was printed to the immediate window (Ctrl+G).
It may be that there is a leading space or some other non-visible
character that is not matching.

(Hint: Always include an Else in every Select Case or multiple If block.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

mattc66 via AccessMonster.com said:
I have the below code on one of my reports. The first "IF" statement fails
to
work if my me.Brand = Amerec. However if it's any of my other If
...me.Brands
below the IF..Me.QuoteExp will work fine.

Can anyone explain why?

Private Sub PageHeader0_Format(Cancel As Integer, FormatCount As Integer)

'The below IF only works if me.brand is NOT AMEREC..
If IsNull(Me.QuoteExp) Then
lblPriceQuote.Visible = False
ElseIf Me.QuoteExp > 0 Then
lblPriceQuote.Visible = True
End If

If Me.Brand = "AMEREC" Then
rptALogo.Visible = True
rptFLogo.Visible = False
rptHLogo.Visible = False
rptPLogo.Visible = False
rptSLogo.Visible = False

ElseIf Me.Brand = "FINNLEO" Then
rptFLogo.Visible = True
rptALogo.Visible = False
rptHLogo.Visible = False
rptPLogo.Visible = False
rptSLogo.Visible = False

ElseIf Me.Brand = "HELO" Then
rptFLogo.Visible = False
rptALogo.Visible = False
rptHLogo.Visible = True
rptPLogo.Visible = False
rptSLogo.Visible = False

ElseIf Me.Brand = "POLAR" Then
rptFLogo.Visible = False
rptALogo.Visible = False
rptHLogo.Visible = False
rptPLogo.Visible = True
rptSLogo.Visible = False

ElseIf Me.Brand = "OEM" Then
rptFLogo.Visible = False
rptALogo.Visible = False
rptHLogo.Visible = False
rptPLogo.Visible = False
rptSLogo.Visible = True

ElseIf Me.Brand = "MCCOY" Then
rptFLogo.Visible = False
rptALogo.Visible = False
rptHLogo.Visible = False
rptPLogo.Visible = False
rptSLogo.Visible = True

End If




End Sub

--
Matt Campbell
mattc (at) saunatec [dot] com

Message posted via AccessMonster.com
 

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