473,406 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Hide Label & Text Control When Field Empty

Hello,

I have been trying, so far in vain, to hide the label and text control in a form when the text control is empty/null.

I have looked at past postings and tried the code below, however I am getting Run-Time Error 438, stating that the object doesn’t support this property or method.

I don't know if I am writing the code to the wrong place or if I have an error in the code itself. Any help is appreciated!!

(I am running Access 2002; The name of my label and text control are both "contractdate")


Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Form_Current()
  3.  
  4. If IsNull(Me!contractdate) Then
  5.     Me!contractdate.Visible = False
  6.     Me!LabelName.Visible = False
  7. Else
  8.     Me!contractdate.Visible = True
  9.     Me!LabelName.Visible = True
  10.  
  11. End If
  12.  
  13. End Sub
Sep 27 '07 #1
8 12821
Denburt
1,356 Expert 1GB
Down and dirty but it should take care of your issue.

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3. Dim MyCnt As Integer
  4. Private Sub Form_Current()
  5. MyCnt = MyCnt + 1
  6. If MyCnt <= 1 Then Exit Sub
  7.  
  8. If IsNull(Me!contractdate) Then
  9.     Me!contractdate.Visible = False
  10.     Me!LabelName.Visible = False
  11. Else
  12.     Me!contractdate.Visible = True
  13.     Me!LabelName.Visible = True
  14. End If
  15. End Sub
  16.  
Sep 27 '07 #2
It worked. Thanks a million!
Sep 27 '07 #3
Denburt
1,356 Expert 1GB
You're welcome, glad I could help.
Sep 27 '07 #4
missinglinq
3,532 Expert 2GB
I'm confused as to why the OP's original code didn't work; it works just fine for me in ACC2000 and ACC2003. I'm also curious as to why adding a dummy variable (MyCnt) makes any difference.

Linq ;0)>
Sep 28 '07 #5
Denburt
1,356 Expert 1GB
I'm confused as to why the OP's original code didn't work; it works just fine for me in ACC2000 and ACC2003. I'm also curious as to why adding a dummy variable (MyCnt) makes any difference.

Linq ;0)>
According to the help file (my bolding for emphasis) "This event occurs both when a form is opened and whenever the focus leaves one record and moves to another. Microsoft Access runs the Current macro or event procedure before the first or next record is displayed."

So if the current event runs BEFORE the record is displayed how can you tell if the field is null or not? Looking at it another way and explaining the error when the form is first opened it runs the current event and no record is there so an error is raised. The Variable is declared for the form as a whole so it retains its value and you skip the current event for this statement only on the very first run after the form is opened, when the form is opened the variable is 0 the current event typically runs I think 3 times when first opened (depending on various circumstances) we only need it to run once for this portion of code. :)

Any questions?
Sep 28 '07 #6
missinglinq
3,532 Expert 2GB
"the current event runs BEFORE the record is displayed"

but not BEFORE the record is actually loaded and it's data available! Access Help is not noted for its clarity, or even for its accuracy in all cases! As I said, the code worked for me in ACC2000 and ACC2003, and similar code has been used since Access time began to do this very task. It's how conditional formatting was accomplished before ACC2000 came along.

The code does need to check for the presence of a new record and make the two controls visible if this is the case.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2.  If Not Me.NewRecord Then
  3.   If IsNull(Me!ContractDate) Then
  4.    Me!ContractDate.Visible = False
  5.    Me!LabelName.Visible = False
  6.   Else
  7.    Me!ContractDate.Visible = True
  8.    Me!LabelName.Visible = True
  9.   End If
  10.  Else
  11.   Me!ContractDate.Visible = True
  12.   Me!LabelName.Visible = True
  13.  End If
  14.  End Sub
The name of my label and text control are both "contractdate")
My guess is that the original error cited might possibly have to do with this statement by the OP. If he started out this code trying to hide the label first, and its name was ContractDate, as he stated, it would raise that very error, because a label cannot be Null. The label's name was changed, you'll note, to LabelName before he posted his code.
Sep 28 '07 #7
Denburt
1,356 Expert 1GB
My apologies for not replying sooner, as you indicated with code posted it should work as you stated. I know that I have had issues in the past and I used the work around that I posted but for this situation I can't seem to see where my thoughts were, now that I review it I am thinking possible ADD or just idiocy (regarding my last post). ;)

In this case I do believe your method would be the approach needed to accomplish his task as requested.

Thanks missinglinq for your clarifications.
Nov 5 '07 #8
missinglinq
3,532 Expert 2GB
As I said, Access Help is not noted for its clarity, or even for its accuracy! You have to remember this at all times! My guess is that the most junior geeks on Billy Bob Gate's development teams are always given the job of documentation! And, of course, many of the events have names that are counter-intuitive! Common sense would tell you that the AfterUpdate event would occur after the update, but of course, that's not true! You can change data, for instance by formatting it, in this event before the record is actually updated! And when the LostFocus event fires, the control hasn't lost focus! Just try to set the focus back on a control thru its LostFocus event; can't be done! And like the Everyready Bunny, the list goes on and on! My approach towards Help is basically the same as that used by our intelligence services, back before politicians took them over; Trust and Verify!

And don't feel bad about not being able to understand what you were thinking about in a post from over a month ago; we've all been there! That's the very reason why documentation is the 4th, 5th and 6th most important thing in software development, right behind backing things up, which is 1st, 2nd and 3rd!

Later!

Linq ;0)>
Nov 5 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Kenneth Grice | last post by:
The Results Form I am working on has a field for price. Some of the records do not have price at this time. Is there a way to program the text box to read, "Contact Whoever for details" if...
4
by: A Traveler | last post by:
Hello all, I have a control i wrote which inherits from asp:label. It worked fine. It extends asp:label with a "For" property which implements the "for" attribute of an html label tag (yes i...
1
by: Lisa Calla | last post by:
Hi, I have a composite control made of a textbox and a label. I want to show either the textbox or the label, and hide the other control on the client side in response to a click. I can run a...
6
by: JohnnyW | last post by:
Hello, I have I simple question that is not clear for me. So, I have a input field (text field) in my html page. User should give input as a string like following 12 345 678,0 If user gives...
4
by: Ben | last post by:
Hi, i have some problem to access from code-behind a label nested into a CreateWizard control. I use a html-table for align purpose only. I try to change the text property of the label with...
2
by: sephali | last post by:
Hello sir, I want to hide the label and text box control which is of null value. The name of the FORM is "Index Entries". The Field name of that text box is the "Legislature". For this I have...
1
by: sephali | last post by:
Sir, I'm using Ms Access 2000 for crearting a database based on the information extracted from government reports. My aim is to preapare an information retrieval system. For this purpose, I...
2
by: Bazza Formez | last post by:
I have a bound field in a DetailsView control that displays free form description type data from my SQL database table (typical data is a couple of paragraphs of written product description being...
18
by: Academia | last post by:
I let the use modify the text of a combobox and then I replace the selected item with the new text (in Keyup event). But if he sets the Text property to an empty string ("") that sets the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.