changing text on a report on a condition

bunji

Registered User.
Local time
Today, 16:05
Joined
Apr 26, 2005
Messages
124
I am trying to change the text to unbound text box dependant on a condition of a field on the report.

So on open if the base is STN the text will be STN's address and if it is LTN then it is LTN address.

I have written some code that adds the address to the box dependant on base, but i get the error message

Compile error:

end if without block if.

Code:
Private Sub Report_Open(Cancel As Integer)
If Me.Base = "STN" Then Me.Address = "STN address here"
End If

End Sub

Once i have got this bit working i will go on to add...

Else If me.Base = "LTN" then me.address = "LTN Address here"

Can anyone explain the error message for me?
 
Hi,

Try using 'Select Case' instead of 'if'.....

Select Case Me!base
Case "STN"
Me!Address = "STN Address here"
Case "LTN"
Me!Address = "LTN Address here"
Case Else
Me!Address = "Nothing Entered Case"l
End Select
 
I tried that but i get the error that it has no value...

Code:
Private Sub Report_Open(Cancel As Integer)

Select Case Me!Base

Case "STN"

    Me!Address.Caption = "STN Address here"

Case "LTN"

    Me!Address.Caption = "LTN Address here"

Case "FAB"

    Me!Address.Caption = "FAB Address here"

End Select

End Sub
 
mmm...ok. Well going back to your original code, the only thing I can see wrong is that you dont need the 'end if' statement because you are using the whole if...then within one line of code.

so your code could simply say...

if me!base = "LTN" then me!Address = "LTN Address"
if me!base = "XXX" then me!Address = "XXX Address"

etc.

if none of the above are true, nothing happens...

A typical end if looks like this...

if CONDITION then
code for true
ELSE
code for false
end if
 
Reverting back to the if statement this is my code

Private Sub Report_Open(Cancel As Integer)
If Me!Base = "LTN" Then Me!Address = "LTN Address"
Else
Me!Address = "STN Address"
End If
End Sub

And i get 'Compile Error: Else without If'

Seems strange to me as that looks normal
 
Ok with some help i got it to work like this...

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

If Base.Properties!Text = "LTN" Then
Address.Caption = " Address A"
Else
Address.Caption = " address B"
End If
End Sub
 

Users who are viewing this thread

Back
Top Bottom