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 
IIF on Button
Harold Laski 
    
4 years ago
I have a form with 2 fields: Amount and Type.  The amount is entered as a payment, for example 85.00. The next field is "Type". It is a dropdown field with 3 choices Cash, Check and CreditCard.  There is also a button called SaveBtn. Pressign that saves the information. What VBA can I use in the button to make sure that it cannot be filled if the "Type" field is left blank?
Adam Schwanz  @Reply  
           
4 years ago
Do you mean it can't be pressed?

If IsNull(Type) or Type="" Then
Msgbox "Enter a Type"
Else
'do what you normally do
End If


TYPE is going to be a reserved word, if that is what your field is called you may want to consider changing the name, or you're going to need to use brackets around it [Type]
Harold Laski OP  @Reply  
    
4 years ago
Thank you. I entered the following as you said and changed the field name to PmtType. It does work.  However, If someone opens the Form they will see the following:
Amount:   $0.00
Pmt Type:

And a button that says "CLOSE".
The problem here is if the user tries to get out of the form afer entering nothing, they cannot.  The only way, once the VBA code is used is to enter something in the PmtType Field.   I was thinking of using an IIF or IF statement that basically says that if the amount field is $0.00 then close, otherwise run the rest of the VBA that you gave me.  I have been at a loss to create this wrinkle in the code.

If IsNull(PmtType) or PmtType="" Then
Msgbox "Enter a Payment Type (Cash, Check, Credit Card)"
Else
DoCmd.Close
End If
Harold Laski OP  @Reply  
    
4 years ago
I recently posted this but did not get the result that I had hoped for. I have a form with 2 fields: PmtAmt and PmtType.  The amount is entered as a payment, for example 85.00. The next field is "PmtType". It is a dropdown field with 3 choices Cash, Check and CreditCard.  There is also a button called SaveBtn. Pressing that saves the information. What VBA can I use in the button to make sure that it cannot be filled if the "Type" field is left blank?
I was offered the following code which works but has is not complete for me.

If IsNull(PmtType) or PmtType="" Then
Msgbox "Enter a Type"
Else
'do what you normally do
End If


The problem that occurred:If someone opens the Form they will see the following:
Amount:   $0.00
Pmt Type:
And a button that says "CLOSE".
The problem here is if the user tries to get out of the form afer entering nothing, they cannot.  The only way, once the VBA code is used is to enter something in the PmtType Field.   I was thinking of using an IIF or IF statement that basically says that if the amount field is $0.00 then close, otherwise run the rest of the VBA that you gave me.  I have been at a loss to create this wrinkle in the code.

Here is the original code:
If IsNull(PmtType) or PmtType="" Then
Msgbox "Enter a Payment Type (Cash, Check, Credit Card)"
Else
DoCmd.Close
End If


I need something andded to the code above that allows me to exit when the "PmtAmt" is either "0.00" or "".
Alex Hedley  @Reply  
           
4 years ago
Is the record becoming dirty?
Adam Schwanz  @Reply  
           
4 years ago
Keep everything in one post it gets super confusing to make multiple posts on the same subject and doesn't get any faster of a response.

Just add to it if you need more
If PmtAmt=0 or IsNull(PmtAmt) Then
'Close the form
Exit Sub
Else
If IsNull(PmtType) or PmtType="" Then
Msgbox "Enter a Type"
Else
'do what you normally do
End If
End If

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/9/2026 1:10:18 AM. PLT: 1s