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 
Optional arguments
Robert Stoner 
    
4 years ago
So I have a function that has multiple optional arguments all Variant.  This way I can just do a isMissing(someValue) doSomething. This works when I call it from the code like myFunction(someValue) the isMissing works.  Now if I use the same function with a form like myFunction(txtBox1,txtBox2).  The first time I run the code it runs fine but then I need to reset txtBox1 and txtBox2.  I can set the text boxes to NULL or "" but not Missing.  That means isMissing will not work.  Right now I am using a Work around I really do not like. By passing the value to a function and turning off error handling then checking if isMissing, isEmpty, or isNull if any return true  the function returns true and I resume error handling.  I can't see the forest for the trees there has to be a cleaner way to do this I'm sure.
Kevin Yip  @Reply  
     
4 years ago
Use an empty string as the default value for your potentially missing argument, so it will never be missing and you never have to use IsMissing(), which is a bit of a pain to use as you've found out.  In all my years I've never used IsMissing(), and I always put default values into optional arguments:

     Function MyFunction(ByVal arg1 As Variant, Optional ByVal arg2 As Variant = "")

To call the function not knowing if arg2 is missing or not (such as when arg2 is from a potentially empty textbox), concatenate the argument with an empty string:

     MyFunction(txtBox1, txtBox2 & "")

That way, the optional argument is always an empty string whether the function is called with an empty textbox or a missing argument.
Robert Stoner OP  @Reply  
    
4 years ago
Kevin thank you for you help.

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 8:17:41 AM. PLT: 1s