Visible problem?

N

Niklas Östergren

Hi!

I have 2 Q!

********
Q No 1.
********

How do I make a lables visible propertie True/False if a control have value
or not?

I´m using wrong syntax here since the code below doesn´t work:
============================================
Private Sub Detalj_Format(Cancel As Integer, FormatCount As Integer)
' Make lines and lables visible = False if no control have value.

If Me.txtEmailAddress = "" And Me.txtPrivateEmailAddress = "" Then
DetailLineNo01.Visible = False
End If

If Me.txtEmailAddress = "" Then
lblEmailAddress.Visible = False
End If

End Sub


********
Q No 2.
********

One control in the report (txtPrivateEmailAddress) show´s Yes/No for a
boolean field in a query. If I display records which dont have anything in
this field (it´s not even created in the table) then I don´t want to show
the lable for this control (lblPrivateEmailAddress)..

The problem I have right now is that if this control isn´t created it
display´s <No> in txtPrivateEmailAddress which is NOT what I want?

The reason to why control txtPrivateEmailAddress don´t have anyting is due
to the table design is one to many relational, like this:

tblPerson........................tblPersonEmailAddress
PersonId (One)----(Many) fkPersonID

The report is populated from a query which I create from a QBF and sometimes
the user don´t selects records which don´t have any related data in
tblPersonEmailAddress. THATS what I mean with that PrivateEmailAddress
doesn´t have anything.

The code I use to try this (but which doesn´t work) is:
======================================
If IsNull(Me.txtPrivateEmailAddress) Then
lblPrivateEmailAddress.Visible = False
End If
======================================

TIA!
// Niklas
 
A

Allen Browne

Replace the label with a text box, and give it a Control Source like this:
=IIf([txtEmailAddress] Is Null, Null, "Email:")

Using Null, this quazi-label Can Shrink if desired.
 
N

Niklas Östergren

Thanks a lot Allen!

// Niklas


Allen Browne said:
Replace the label with a text box, and give it a Control Source like this:
=IIf([txtEmailAddress] Is Null, Null, "Email:")

Using Null, this quazi-label Can Shrink if desired.

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

Reply to group, rather than allenbrowne at mvps dot org.
Niklas Östergren said:
Hi!

I have 2 Q!

********
Q No 1.
********

How do I make a lables visible propertie True/False if a control have value
or not?

I4m using wrong syntax here since the code below doesn4t work:
============================================
Private Sub Detalj_Format(Cancel As Integer, FormatCount As Integer)
' Make lines and lables visible = False if no control have value.

If Me.txtEmailAddress = "" And Me.txtPrivateEmailAddress = "" Then
DetailLineNo01.Visible = False
End If

If Me.txtEmailAddress = "" Then
lblEmailAddress.Visible = False
End If

End Sub


********
Q No 2.
********

One control in the report (txtPrivateEmailAddress) show4s Yes/No for a
boolean field in a query. If I display records which dont have anything in
this field (it4s not even created in the table) then I don4t want to show
the lable for this control (lblPrivateEmailAddress)..

The problem I have right now is that if this control isn4t created it
display4s <No> in txtPrivateEmailAddress which is NOT what I want?

The reason to why control txtPrivateEmailAddress don4t have anyting is due
to the table design is one to many relational, like this:

tblPerson........................tblPersonEmailAddress
PersonId (One)----(Many) fkPersonID

The report is populated from a query which I create from a QBF and sometimes
the user don4t selects records which don4t have any related data in
tblPersonEmailAddress. THATS what I mean with that PrivateEmailAddress
doesn4t have anything.

The code I use to try this (but which doesn4t work) is:
======================================
If IsNull(Me.txtPrivateEmailAddress) Then
lblPrivateEmailAddress.Visible = False
End If
======================================

TIA!
// Niklas
 
D

Douglas J. Steele

Allen's given you a working solution. I just thought I'd offer some
explanations of why you had problems with your code.

You're setting the Visible property to False in certain conditions, but you
never set it back to True if the conditions aren't met after that.

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
' Make lines and lables visible = False if no control have value.

If Me.txtEmailAddress = "" And Me.txtPrivateEmailAddress = "" Then
DetailLineNo01.Visible = False
Else
DetailLineNo01.Visible = True
End If

If Me.txtEmailAddress = "" Then
lblEmailAddress.Visible = False
Else
lblEmailAddress.Visible = True
End If

End Sub

or

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
' Make lines and lables visible = False if no control have value.

DetailLineNo01.Visible = (Me.txtEmailAddress <> "" Or
Me.txtPrivateEmailAddress <> "")

lblEmailAddress.Visible = (Me.txtEmailAddress <> "")

End Sub

Actually, if there's a chance that your field might be Null (not "") and you
want to trap for that, the following is better:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
' Make lines and lables visible = False if no control have value.

DetailLineNo01.Visible = (Len(Me.txtEmailAddress & vbNullString) > 0 _
Or Len(Me.txtPrivateEmailAddress & vbNullString) > 0)

lblEmailAddress.Visible = (Len(Me.txtEmailAddress & vbNullString) > 0)

End Sub
 
N

Niklas Östergren

Thank´s a lot Douglas!

I realy apreciate you help and I´ll chooose tha last example since there
actually are a chanse that the fields may be Null.

// Niklas
 

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