Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    wrayman is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2016
    Posts
    46

    Need to end sub (stop everything from happening and just exit)

    Got a situation where if it is true need the option of ending the sub



    I know this isn't working because I never get the msgbox STOP and then after pressing NO the code runs normally

    Here is a code snipet.

    I have used this before, I must be forgetting something.

    Anyway if the msgbox response is vbNo I need to stop the sub, go to End Sub , or Exit Sub

    Code:
    ume = Parsed("results")(1)("items")(1)("uid")
    
    pn = "41290"
    Debug.Print pn
    'MsgBox "Do you wish to continue?", vbYesNo, "Continue"
    rs4.MoveFirst
    Do Until rs4.EOF
    If rs4!UID = ume Then
    MsgBox "Exists: Is this an UPDATE?", vbYesNo
    If Response = vbNo Then
    MsgBox "stop"
    Exit Sub

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,931
    perhaps something like

    Code:
    If rs4!UID = ume Then
        if MsgBox ("Exists: Is this an UPDATE?", vbYesNo)= vbNo Then
            MsgBox "stop"
            Exit Sub
        end if
    ...
    ...

  3. #3
    wrayman is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2016
    Posts
    46
    Yep works great, if if if...., lol, Thanks so much!

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    The If...Then...Else Statement has 2 forms: single line and block.

    It looks like you are using the block form but are missing the "End If" line for the 2 IF statements. And I would guess you do not have the line "Option Explicit" at the top of the module.

    On top of that, you have a DO loop but never move to the next record.
    Maybe try:
    Code:
        ume = Parsed("results")(1)("items")(1)("uid")
    
        pn = "41290"
        Debug.Print pn
        'MsgBox "Do you wish to continue?", vbYesNo, "Continue"
        rs4.MoveFirst
        Do Until rs4.EOF
            If rs4!UID = ume Then
                If MsgBox("Exists: Is this an UPDATE?", vbYesNo) = vbNo Then
                    MsgBox "stop"
                    Exit Sub
                End If
            End If
            rs4.MoveNext
        Loop

  5. #5
    wrayman is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2016
    Posts
    46
    I had it, but didn't "copy it" here is the full snip
    Last edited by wrayman; 11-21-2016 at 06:10 PM. Reason: Update coming, totally wrong

  6. #6
    wrayman is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2016
    Posts
    46

    Totally Messed that up

    Sorry for the slop, was inserting code into another statement: here is the full code

    It seems to work, thanks! See anything else wrong with it?

    Code:
    ume = Parsed("results")(1)("items")(1)("uid")Debug.Print ume
    
    
    pn = "735075"
    Debug.Print pn
    
    
      'MsgBox "Do you wish to continue?", vbYesNo, "Continue"
        rs4.MoveFirst
        Do Until rs4.EOF
            If rs4!UID = ume Then
                If MsgBox("Exists: Is this an UPDATE?", vbYesNo) = vbNo Then
                    MsgBox "stop"
                    Exit Sub
                End If
            End If
            rs4.MoveNext
        Loop
    
    
    rs4.MoveFirst
    Do Until rs4.EOF
    If rs4!PartNumber = pn Then
    rs4.Edit
    rs4!UID = ume
    rs4.Update
    End If
    rs4.MoveNext
    Loop

  7. #7
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Nope. Ajax nailed it again...

  8. #8
    wrayman is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2016
    Posts
    46

    One more thing (maybe)

    This just doesn't look right, but it works....

    Anyway I need to delete records from several table in the ELSE clause, I have no clue without starting a cascade of if statements?

    Any help?

    Code:
    ume = Parsed("results")(1)("items")(1)("uid")
    Debug.Print ume
     
    pn = "735075"
    Debug.Print pn
     
      'MsgBox "Do you wish to continue?", vbYesNo, "Continue"
        rs4.MoveFirst
        Do Until rs4.EOF
            If rs4!UID = ume Then
                If MsgBox("Exists: Is this an UPDATE?", vbYesNo) = vbNo Then
                    MsgBox "stop"
                    Exit Sub
                Else
                    rs2.MoveFirst
                    Do Until rs2.EOF
                        If Not IsNull(rs2!UID) And rs2!UID = ume Then
                            rs2.Delete
                            End If
                            rs2.MoveNext
                    Loop
                End If
            End If
        rs4.MoveNext
        Loop
     
    rs4.MoveFirst
        Do Until rs4.EOF
                If rs4!PartNumber = pn Then
                    rs4.Edit
                    rs4!UID = ume
                    rs4.Update
                End If
            rs4.MoveNext
        Loop

  9. #9
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Anyway I need to delete records from several table in the ELSE clause, I have no clue without starting a cascade of if statements?
    Without knowing a lot more about your dB, do all of the tables have a field "ume"?

    Not sure what you are trying to do, but maybe you could execute delete queries?

    Code:
    CurrentDb.Execute "DELETE rs2.* FROM rs2 WHERE rs2.UID = " & ume & ";", dbFailOnError
    Change "rs2" to the table name/query name if many tables.......

  10. #10
    wrayman is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2016
    Posts
    46
    Yes all the fields during the update have the same ume., I guess I could just stack the delete query?

  11. #11
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    By "stack", you mean execute one query after another? Yes, I have....

  12. #12
    wrayman is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2016
    Posts
    46

    Not working

    Good idea, but I can't get it to work:

    Code:
     CurrentDb.Execute "DELETE pricing.* FROM pricing WHERE pricing.UID =  " & ume & ";", dbFailOnError
               
             CurrentDb.Execute "DELETE rs2.* FROM rs2 WHERE rs2.UID = " & ume & ";", dbFailOnError
    I get
    Click image for larger version. 

Name:	error3075.PNG 
Views:	12 
Size:	2.6 KB 
ID:	26495


    ume is String , tried several options but keep getting errors, that UID is in the table pricing.

    Any suggestions?

  13. #13
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Try

    CurrentDb.Execute "DELETE pricing.* FROM pricing WHERE pricing.UID = '" & ume & "';", dbFailOnError
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  14. #14
    wrayman is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2016
    Posts
    46
    Thanks for the ' " rescue " ' , appreciated

  15. #15
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    No problem, it looked like Steve was offline. Too cold up there probably.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 10-28-2016, 08:37 AM
  2. Replies: 2
    Last Post: 12-20-2012, 03:06 PM
  3. If New Record Stop Code Exit Sub
    By burrina in forum Forms
    Replies: 1
    Last Post: 12-19-2012, 01:02 PM
  4. Replies: 2
    Last Post: 11-29-2009, 12:00 PM
  5. I need help with weird stuff happening on a DB
    By makotoshishio in forum Access
    Replies: 9
    Last Post: 04-02-2009, 12:20 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