473,396 Members | 1,773 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,396 software developers and data experts.

Hiding a Text Box depending on whether another field is empty or not

I'm really new. I'm working in Access 2010. I did the following and my [Probation Ends:] is always invisible now. I have a Label Box that I changed to a Text Box. I set the Format for Visible to Yes and Can Shrink to Yes. The Control Source is [Probation Ends:] and that is the Name also. I added an Event as follows:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Probation_Ends__Click()
  2.  
  3.     If IsNull(Me![Probation End Date]) Then
  4.         Me![Probation Ends:].Visible = False
  5.     Else
  6.         Me![Probation Ends:].Visible = True
  7.     End If
  8.  
  9. End Sub
If the [Probation End Date] is null, then I want the [Probation Ends:] box to be invisible. What do you think is the problem?
Aug 18 '15 #1

✓ answered by Seth Schrock

Change the name of your textbox to be different than it Control Source. Then put your code (with the new control name) in the Detail section's OnFormat event.

14 1059
Seth Schrock
2,965 Expert 2GB
Try putting your code in the form's OnCurrent event.
Aug 18 '15 #2
This is a report. I don't see OnCurrent...
Aug 18 '15 #3
Seth Schrock
2,965 Expert 2GB
Change the name of your textbox to be different than it Control Source. Then put your code (with the new control name) in the Detail section's OnFormat event.
Aug 18 '15 #4
I changed the name to PE and I moved the event to "On Enter", but it still didn't work. I didn't see an OnFormat event on the Event tab. Here is the changed event...

Expand|Select|Wrap|Line Numbers
  1. Private Sub PE_Enter()
  2.  
  3.     If (Me![Probation End Date]) = "" Then
  4.         Me!PE.Visible = True
  5.     Else
  6.         Me!PE.Visible = False
  7.     End If
  8.  
  9. End Sub
Aug 18 '15 #5
I had also changed the IsNull out and put = "". Didn't work...
Aug 18 '15 #6
Seth Schrock
2,965 Expert 2GB
You are looking the control's event list, not the report's detail section (or whatever section your textbox is in). Click on an empty space beside your textbox and then look at your event list. Also, you need to change the reference in your code to be Me.PE not Me.[Probation End Date].
Aug 18 '15 #7
I found it. I don't understand why all of the controls would be pointed to PE? It is only to print if the Probation End Date is empty.
Aug 18 '15 #8
Got it to work!!! Yea!! I don't use a VBA code. I just put the following in the Control Source line and use the Control Source Names, not the Names of the fields.
Expand|Select|Wrap|Line Numbers
  1. =IIf([PROBATION END DATE] Is Null,Null,"PROBATION ENDS:")
Aug 18 '15 #9
Seth Schrock
2,965 Expert 2GB
That doesn't hide the control, it just makes it so that there isn't anything in it. But if that is all you need then great.
Aug 18 '15 #10
NeoPa
32,556 Expert Mod 16PB
I've changed the post selected as Best Answer for a number of reasons. Not least of which is that it actually answers the question posed - rather than simply providing a way round the issue.
Aug 19 '15 #11
NeoPa
32,556 Expert Mod 16PB
As a tip, you can also simplify the code greatly :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Detail_Format()
  2.     Me.[Probation Ends:].Visible = Not IsNull(Me.[Probation End Date])
  3. End Sub
Aug 19 '15 #12
I tried adding the code and it wouldn't work. Seth's didn't work either.
Aug 19 '15 #13
Seth Schrock
2,965 Expert 2GB
Based on the code that you provided, you didn't try exactly what I had said as it wasn't in the report detail section's OnFormat event.
Aug 19 '15 #14
NeoPa
32,556 Expert Mod 16PB
LadyScot:
Seth's didn't work either.
I can confirm that Seth's suggestion itself does work. I can't say why it was that it didn't work for you as I can't see exactly what it was that you tried. It does seem clear, however, that it wasn't exactly as he suggested.

There are a number of reasons why it might not work for you - from all VBA code being disabled due to security restrictions to your placing the code in the wrong container (module), or even not setting the event property up correctly to access the code.
Aug 20 '15 #15

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

Similar topics

1
by: Gabriël | last post by:
Hi All, I've created an eventhandler for ItemdataBound and ItemCreated, but when I access "e.Item.Cells.Text" it's always empty. BUT, when I assign a value to this empty field (while being in...
4
by: Paul J. Lucas | last post by:
I have a simple form that contains an INPUT element that has an initial value. <form name="Form"> <input name="Number" type="text" value="Hello"> </form> When the form loads, I want all of...
3
by: jfilan | last post by:
index.php?action=searchresults&pclass=1 index.php?action=searchresults&pclass=2 index.php?action=searchresults&pclass=3 index.php?action=searchresults&pclass=4...
12
by: Ste | last post by:
Hi there, I've got a website with a list of Frequently Asked Questions, so there's a question and answer in a long list down the page. Can anyone recommend a simple script that would allow me...
4
medim84
by: medim84 | last post by:
How to format text in memo field for predefine text, using - default value - expression builder? For e.g. new row, bold text, font size… Thanks
8
by: elastreto | last post by:
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...
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: SWATI AGARWAL | last post by:
How can we set the size of a button in java when the text on it is empty. setbounds ,setsize ,setprefferedsize are the options that i tried but i failed to get the desired output.
6
by: ammar yasir | last post by:
how to justify text in memo field of a form and a report? i need some sort of code that keeps the text in memo field justified. there are only 3 options of text align, right,left, distributed. i want...
14
by: CD Tom | last post by:
I have a customer in the Netherlands that is getting the following error "Text file specification Field separator matches decimal separator or text delimiter" This happens when I try and run 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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
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,...

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.