Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Visible Property
Kyle Rapp 
    
2 years ago
Hey guys, In VBA, when setting a field's visibility based on some criteria, is it absolutely necessary to use an ELSE statement?  

For example:

    If me.ContactType = "Employee" then
       me.JobTitle.visible = True

    Else
       me.JobTitle.visible = False
    
    End if

It seems that if I omit the Else statement it does not work as expected.  I would think that the default visibility on the field's property would apply unless the criteria of the IF statement applies.  I would think the same holds true for the .enabled property.

Thanks,
Kyle


Sami Shamma  @Reply  
             
2 years ago
you changed the default with your code. that is why you need the "else"
Kevin Robertson  @Reply  
          
2 years ago
If Then

Also if you are referring to the current Form you don't need Me. everywhere.
Note: The dot is used for Properties and Methods. See this video: Bang! v Dot.
Kyle Rapp OP  @Reply  
    
2 years ago
ok got it.  So, if the default visibility is set to false,  but the criteria of the IF statement is met, (resulting in JobTitle.visible = true, even without the ELSE statement the default should change from false to true correct?  And if the criteria is not met, the visibility should remain as false correct?
Kevin Yip  @Reply  
     
2 years ago
A default value is only used *the moment you create a new record*.  When that moment is passed, a default value is no longer used.  Any subsequent changes to the field values have to be done via code and/or user entries.
Kevin Robertson  @Reply  
          
2 years ago
If ContactType = "Employee" then
   JobTitle.Visible = True
Else
   JobTitle.Visible = False
End If


In your example if the ContactType is "Employee" then JobType will be visible, otherwise it will NOT be visible.
If you don't include the Else clause then JobType will ALWAYS be visible because your code would not be telling Access to make that field not visible.
Kyle Rapp OP  @Reply  
    
2 years ago
Hi Kevin Y, sorry, when I said "default value" I meant "default visibility setting".  I was just looking for confirmation that the visibility would be whatever you put in the control's visibility property, unless VBA code says otherwise.  For example, by default, controls are always visible.  So, if a condition in VBA is met and the property is set to "false" then that would override the visibility setting of "true" on the control's property sheet.  Sorry for the confusion.

Kevin R, I understand thank you.  I would have thought that the visibility was true only if the IF statement criteria was met, meaning Access would assume visiblity is false unless the IF statement criteria is met.  Not sure why MSFT designed it that way but it is what it is.  (unless I'm misunderstanding something, which is highly likely)  :-)  Thanks again guys.
Kevin Yip  @Reply  
     
2 years ago
The settings on the property sheets can also be seen as "defaults," since those settings are used whenever a form is first opened, and/or a record is first created.  Afterwards, those defaults are no longer relevant.
Richard Rost  @Reply  
          
2 years ago
Correct. And if you're putting code in the On Current event, you're going to need the Else as you move thru records and need to switch properties on/off based on the next record.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/7/2026 3:23:13 AM. PLT: 0s