Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8104753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:57:28+00:00 2026-06-05T23:57:28+00:00

So I’ve created a form in Access, which has a combo box and a

  • 0

So I’ve created a form in Access, which has a combo box and a text box. The form calculates some things after pressing a button but either both the combo box and the text box have to be filled, or neither of them can be filled. What I’d like to do is put in a condition so that if only one of them is filled, a Message Box would popup explaining to fill both boxes and then proceed to stop the code. I understand how to do the message box part, but right now it’s showing the message box and then proceeding on with the code which produces an error.

I’ve done some research but most of what I’m finding has to do with temporarily pausing the form, not completely stopping it.

I have a couple of ideas on how to do this, but I’m having trouble executing them and frankly I’m not even sure they’ll work. My first plan was to copy and paste all the calculation parts from the procedure, create a new procedure with them, create an if statement in the button clicking procedure and call the new procedure if it passes the if statement. My second plan is a little more tedious but I’m fairly confident it’ll work. It’s just surrounding the entire code with an if statement, if it passes execute the code, if it doesn’t, do nothing and have it reach the end of the procedure and end itself. My only issue with the second one is I have a LOT of code beforehand, and I’d rather not waste a large amount of time re-indenting lines if I can help it, but I have that as a backup if I can’t find a better way.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T23:57:35+00:00Added an answer on June 5, 2026 at 11:57 pm

    You have a few options available to you:

    1. As you suggested, take the code presently tied to the button click event and move it to a new sub procedure. In the button click event perform your validation and if everything passes invoke the sub procedure. If not, show your messagebox.
    2. Assuming you have proper error handling in the button click event, raise an error instead of showing the messagebox. This will move the control flow to your error handler in the procedure.
    3. After displaying the message box, use either Exit Sub or Exit Function to stop code execution.

    Option 1 is probably the best approach as it promotes better coding practices. If you have long sub routines it could be a sign that you need to break the sub routine into smaller units of work, which makes code reuse and debugging much easier.

    Option 2 is appropriate in some cases where the condition truly is an error. One could argue that failing a validation test is a form of an error condition.

    Personally, I tend to avoid using Exit Sub and Exit Function (Option 3) in most cases because I like to have a single point in a sub routine where the routine exits and passes control back to the calling procedure. Having multiple exit points within a routine is a sign that you need to refactor your code \ rethink the logic you are applying. Sometimes it can’t be helped, but often you create a situation that is more difficult to debug.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a text area in my form which accepts all possible characters from
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.