Results 1 to 7 of 7
  1. #1
    caniread is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2015
    Posts
    86

    Dialog form cancel button to exit sub from another form

    I have a dialog box that opens when a box is checked. How would I tell the onclick event that the cancel button was pressed so that I can cancel the rest of the event?

    I have been trying to figure it out and here is as far as I have gotten.

    Private Sub Check204_AfterUpdate()
    DoCmd.OpenForm "FRM_ROBOT_VERI", , , , , acDialog
    If Forms![FRM_ROBOT_VERI]![Command0] = True Then
    Exit Sub
    Else
    End If



    Thank you for the help.
    Last edited by caniread; 07-06-2017 at 12:11 PM.

  2. #2
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    What does your dialog form do? Would a MsgBox work just as well (easier to code)?

  3. #3
    caniread is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2015
    Posts
    86
    Dialog box has a combo box to select names. As far as I know cant be done in a msgbox. If they hit cancel I need it to stop running the code that initiated on the other form (not the dialog form).

  4. #4
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    OK. Then I need to know more: what happens to the names that they are selecting, are they being stored somewhere or displayed, what needs to happen when they click ok as opposed to cancel.

    Does code stop executing until the form is closed? I am not sure about that, you may have to put the code into the OnClose of the dialog form.

  5. #5
    caniread is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2015
    Posts
    86
    Dialog form only has OK Cancel and the combo box. Hitting ok runs this code.
    Private Sub Command1_Click()
    Forms![ROBOT]![CBO_ROBOT_VERIFIED] = Me.CBO_VERIFIED
    DoCmd.Close
    End Sub

    When the dialog box closes more code on the other form continues.
    I need it to exit the sub on the other form if they hit cancel.

  6. #6
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Your Command1 click routine sets that field. Check to see if it has been set or is null.

  7. #7
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Not sure I agree that the Command1_Click() event helps as written since it sets the value of a control or field to be the value chosen from the combo.
    Lot's of ways to do this, I think. Simplest might be to have a hidden unbound text box on the first form. Set its value according to the button that was clicked on the dialog form. When the dialog closes, execution returns to the first form, where you test the value. You shouldn't have to requery the textbox, but watch for that.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 11-17-2016, 10:55 AM
  2. Cancel an entry and exit form
    By michwh1 in forum Access
    Replies: 3
    Last Post: 03-28-2013, 03:13 PM
  3. Can't cancel the ‘find’ dialog in modal form
    By AndrewAfresh in forum Access
    Replies: 0
    Last Post: 09-23-2011, 11:12 AM
  4. Replies: 9
    Last Post: 08-06-2011, 02:10 PM
  5. Replies: 0
    Last Post: 02-15-2011, 01:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums