1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Call Button not working properly in MS Access

Discussion in 'Business Applications' started by DamnDaniel, Sep 28, 2016.

Thread Status:
Not open for further replies.
  1. DamnDaniel

    DamnDaniel Thread Starter

    Joined:
    Mar 18, 2016
    Messages:
    4
    First Name:
    Pranay
    Hey Guys,

    I'm still fairly new in vba coding :p and need some help!!

    Situation:
    I have two buttons on my form - SAVE and CLOSE. I have added certain validations on SAVE button and want that whenever someone Clicks on CLOSE, it calls the SAVE button first and then close the form only if all validations are satisfied. When I use the below mentioned code, it calls the SAVE button perfectly and gives pop-ups wherever validations are not met. However, it does not stop there and still closes the form. And yes, every validation in SAVE button already has "Exit Sub" added to it. :)

    Code:

    Private Sub Command61_Click()

    Call Command41_Click

    DoCmd.Close acForm, "QAWorkflow", acSaveYes
    DoCmd.OpenForm "WelcomeForm", acNormal

    Thanks in Advance!
     
  2. OBP

    OBP Trusted Advisor

    Joined:
    Mar 8, 2005
    Messages:
    19,830
    You need to set a Public Variable that can pass it's value back to the Command61_Click() sub.
    Then you would have a line of code after the Call line with something like

    If dontcloseform = 1 then exit sub.

    the variable dontcloseform would be set to zero before the Call line
    ie
    dontcloseform = 0

    then in the Command41_Click sub instead of just exit sub you would have
    dontcloseform = 1
    exit sub
    Thus when the code comes back from the Command41_Click sub the new line would trigger an exit code before the form is closed.

    ps I assume that you are aware that Access automatically saves any new records or edited records and that if you do not want the data saved you have to "undo" the record.
     
    Last edited: Sep 28, 2016
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1178815

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice