View Full Version : Solved: If Structure
tibby812
06-07-2004, 04:21 PM
Hi, im trying to write a condition in an Access report. I have a checkbox field in my report that shows me the person owes me money. Now i would like to write an If statement saying that
if the checkbox is checked then
the lable of the checkbox is visible.
Now i've tried
If chkBox.Value = True Then
lblChkBox.Visible = True
End If
Any Suggestions!! Thanx
I forgot to mention, the field in the table is a Yes/No field. It is already populated with data.
Anne Troy
06-07-2004, 04:51 PM
Sorry if I'm wrong, tibby. I'm not good with this stuff.
Try this syntax, changing the values, of course:
'checked = 0
'unchecked = -1
If (MyField = -1 Or IsNull(MyField)) Then
Me.MyLabel.Visible = False
Me.MyField.Visible = False
Else
Me.MyLabel.Visible = True
Me.MyField.Visible = True
End If
Stromma
06-07-2004, 04:52 PM
Hi tibby
Are you trying to hide the CheckBox? if so try:
If CheckBox1 = True Then
CheckBox1.Visible = True
End If
If CheckBox1 = False Then
CheckBox1.Visible = False
End If
If you just want to change the Caption try:
If CheckBox1 = True Then
CheckBox1.Caption = "Visible"
End If
If CheckBox1 = False Then
CheckBox1.Caption = "Hidden"
End If
/Roger
tibby812
06-07-2004, 04:55 PM
Im not trying to change the caption or trying to hide it, i can do those things, but dreamboat is on the right track, i basically want to say if the field is yes, then display a lable. When i put
If chkBox.Value = True Then
lblChkBox.Visible = True
End If
it tells me that there is no value
The exact error is run-time 2427 , You enetered an expression that has no value
tibby812
06-07-2004, 05:44 PM
Thought this might help
I have a table called Main Table
i have 5 fields
Name = txt
ID = AutoNum
Over21 = Yes/No
HasComputer = Yes/No
HasCellPhone = Yes/No
Ok........now enter 5 people in the table and check the boxes.
Now Create a report thats bound to MAIN TABLE
In the detail, add all the fields.
Now field Over21 , HasComputer, HasCellPhone are check boxes. These check boxes have labels.
Now i have code saying
Private Sub Report_Open(Cancel As Integer)
chkOver21.Visible = False
chkHasComputer.Visible = False
chkHasCellPhone.Visible - False
Now this also hides the labels that are bound to these fields, but i want to say if the field chkOver21 is checked , display the corresponding label.
if chkOver21.Value = Yes Then
lblOver21.Visible = True
end if
Now you may ask why i don't try exactly what i wrote to you, but i did, and it gives me a "run-time error 2427, You enetered an expression that has no value"
Anne Troy
06-07-2004, 05:48 PM
Did you try the syntax I gave?
What happens then?
PS: See the little VBA button just above the reply box.
Use it to make your VBA code look like code. Click it, and paste the code between the tag sets. :)
tibby812
06-07-2004, 05:50 PM
Drreamboat,
I tried the code that you gave me and it gives me the same error. 2427 Runtime Error
jamescol
06-07-2004, 10:33 PM
I placed this in the AfterUpdate event of the checkbox and it works fine (on Off 2003)
If cbox.Value = True Then
lblCbox.Visible = True
ElseIf cbox.Value = False Then
lblCbox.Visible = False
End If
Zack Barresse
06-07-2004, 11:25 PM
couldn't you shorten that James to:
If cbox.Value = True Then
lblCbox.Visible = True
End If
lblCbox.Visible = False
???
jamescol
06-07-2004, 11:35 PM
Hmm - I think in your example, even when the IF statement executes, the
lblCbox.Visible = False
line will execute every time. So lblCbox.Visible will always be set to False.
It's late, so maybe I'm just not reading it right.
jamescol
06-07-2004, 11:36 PM
You could shorten it like
If cbox.Value = True Then
lblCbox.Visible = True
Else
lblCbox.Visible = False
End If
Zack Barresse
06-08-2004, 12:08 AM
my line of thinking was, it's checkbox, right? I mean, we're looking at boolean values, so it's either True or False. You only need the one if statement and no Else.
But it's late for me too, so, I could be wrong.
edit: disregard, I'm WAY wrong - too tired. :eek:
TonyJollans
06-08-2004, 01:44 AM
Ok, I've scanned this thread a bit quickly so I may have missed something.
Putting code for this in the Report_Open Event isn't going to do a lot of good. You want to set the properties in the Detail_Format Event.
As all your values are Boolean, you can also shorten it something like this ..
chkOver21.Visible = chkOver21
chkHasComputer.Visible = chkHasComputer
chkHasCellPhone.Visible = chkHasCellPhone
lblOver21.Visible = chkOver21
lblHasComputer.Visible = chkHasComputer
lblHasCellPhone.Visible = chkHasCellPhone
SJ McAbney
06-08-2004, 03:52 AM
You could shorten it like
If cbox.Value = True Then
lblCbox.Visible = True
Else
lblCbox.Visible = False
End If
Or:
Me.lblCbox.Visible = Me.Cbox
;)
tibby812
06-08-2004, 07:58 AM
To Tony Jollans, your advice inspired me and i wanted to thank you for your info.
This is what i did,
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
chkOver21.Visible = chkOver21
lblOver21.Visible = chkOver21.Visible
End Sub
SJ McAbney
06-08-2004, 08:22 AM
To Tony Jollans, your advice inspired me and i wanted to thank you for your info.
This is what i did,
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
chkOver21.Visible = chkOver21
lblOver21.Visible = chkOver21.Visible
End Sub
One thing:
Try never to imply what you are referred to - always be explicit. Include the reference to the current report's Class (Me.) - it helps the speed of the database once compiled. It simply means that when running the database doesn't have to find where the chkOver21 and lblOver21 objects are. By including the explicit reference to the report's class, it knows immediately reference these objects on that report.
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Me.chkOver21.Visible = Me.chkOver21
Me.lblOver21.Visible = Me.chkOver21.Visible
End Sub
Anne Troy
06-09-2004, 10:11 AM
Hey, tib?
Is this resolved yet?
It appears to be...
DarkSprout
08-04-2008, 04:18 AM
Instead of
If Me.cbox.Value = True Then
lblCbox.Visible = True
Else
lblCbox.Visible = False
End If
Try Some Simpler Code:
[lblCbox].Visible = [cbox]
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.