UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Control Visible    
 
   
mike60smart
post Mar 30 2012, 11:15 AM
Post #1

UtterAccess VIP
Posts: 8,472
From: Dunbar,Scotland



Hi Everyone

I want an unbound textbox named txtCancelled to display "Cancelled Member"
If the Control MembershipCancelled contains a Date

I tried using this in the On Load of the Form

Private Sub Form_Load()
If Me.MembershipCancelled = Null Then
Me.txtCancelled.Visible = False
Else
Me.txtCancelled.Visible = True
End If
End Sub

I also tried = ""

When I navigate to any record the Cancelled control stays visible at all times

Where should I place this Event???

Your help appreciated
Go to the top of the page
 
+
Jeff B.
post Mar 30 2012, 11:21 AM
Post #2

UtterAccess VIP
Posts: 8,170
From: Pacific NorthWet



If you're relying on the contents of a field/control for a record to which the form is bound, try using the OnCurrent event.
Go to the top of the page
 
+
MikeLyons
post Mar 30 2012, 11:21 AM
Post #3

UtterAccess VIP
Posts: 1,857
From: BC, Canada



The reason it doesn't change is because your code is in the Form_Load event which rns when the form is loaded. To make it run each time you navigate to a new record, put it in the Form_Current event.

Mike
Go to the top of the page
 
+
BruceM
post Mar 30 2012, 11:39 AM
Post #4

UtterAccess VIP
Posts: 2,451
From: Downeast Maine



And to reduce the code to one line:

Me.txtCancelled.Visible = Not (Me.MembershipCancelled = Null)
Go to the top of the page
 
+
mike60smart
post Mar 30 2012, 11:42 AM
Post #5

UtterAccess VIP
Posts: 8,472
From: Dunbar,Scotland



Hi Bruce

Tried this one liner:-

Private Sub Form_Current()
Me.txtCancelled.Visible = Not (Me.MembershipCancelled = Null)
End Sub

Gives me Runtime Error 94 - Invalid use of Null

Any suggestions??

Go to the top of the page
 
+
mike60smart
post Mar 30 2012, 11:45 AM
Post #6

UtterAccess VIP
Posts: 8,472
From: Dunbar,Scotland



Hi Bruce

Also tried this

If Me.MembershipCancelled Is Not Null Then
Me.txtCancelled.Visible = True
Else
Me.txtCancelled.Visible = False
End If

Gives Runtime error 424 - Object required ??

Go to the top of the page
 
+
theDBguy
post Mar 30 2012, 11:47 AM
Post #7

Access Wiki and Forums Moderator
Posts: 48,051
From: SoCal, USA



Hi Mike,

What version of Access are you using? Please remember to select the version number when posting questions in case it becomes relevant to the discussion.

If this is a calculated field, I recommend you don't store the value in the table. To just display something like that on the form, you can use an Unbound textbox with the following Control Source:

=IIf(IsDate([MembershipCancelled]),"Cancelled Member","Active Member")

Just my 2 cents... (IMG:style_emoticons/default/2cents.gif)
Go to the top of the page
 
+
MikeLyons
post Mar 30 2012, 11:50 AM
Post #8

UtterAccess VIP
Posts: 1,857
From: BC, Canada



QUOTE (BruceM @ Mar 30 2012, 09:39 AM) *
And to reduce the code to one line:

Me.txtCancelled.Visible = Not (Me.MembershipCancelled = Null)


That won't work because technically Null is not a value that can be tested, but rather it is a non-value.

Try:

CODE
Me.txtCancelled.Visible = Not IsNull(Me.MembershipCancelled)


Alternatively, I often use:

CODE
Me.txtCancelled.Visible = (Me.MembershipCancelled & "" <> "")


Mike
Go to the top of the page
 
+
mike60smart
post Mar 30 2012, 11:52 AM
Post #9

UtterAccess VIP
Posts: 8,472
From: Dunbar,Scotland



Hi theDBGuy

A2010

When I used your String in an Unbound Textbox then I get this error #Name?

Thoughts??

Go to the top of the page
 
+
mike60smart
post Mar 30 2012, 11:56 AM
Post #10

UtterAccess VIP
Posts: 8,472
From: Dunbar,Scotland



Hi Mike

This works

Me.txtCancelled.Visible = Not IsNull(Me.MembershipCancelled)

Many thanks everyone for your help

Go to the top of the page
 
+
theDBguy
post Mar 30 2012, 11:59 AM
Post #11

Access Wiki and Forums Moderator
Posts: 48,051
From: SoCal, USA



QUOTE (mike60smart @ Mar 30 2012, 09:52 AM) *
Hi theDBGuy

A2010

When I used your String in an Unbound Textbox then I get this error #Name?

Thoughts??

Make sure you use the name of the control. Please remember what I said about storing calculated fields in your table.

Good luck!
Go to the top of the page
 
+
BruceM
post Mar 30 2012, 12:33 PM
Post #12

UtterAccess VIP
Posts: 2,451
From: Downeast Maine



Sorry about that = Null thing. I know better. I must have reverted early to my weekend brain. (IMG:style_emoticons/default/blush.gif)
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 23rd May 2013 - 03:37 PM