Results 1 to 5 of 5
  1. #1
    Paul H's Avatar
    Paul H is offline Expert
    Windows 10 Access 2016
    Join Date
    Sep 2011
    Location
    Richmond, VA
    Posts
    591

    An odd duck

    I have a data entry form with 9 buttons that has been getting buggy.



    Attachment 43649

    The first step is to retrieve a record.
    Click image for larger version. 

Name:	Orgination Undo 1a.JPG 
Views:	25 
Size:	39.5 KB 
ID:	43652

    Then change a value.
    Click image for larger version. 

Name:	Orgination Undo 1b.JPG 
Views:	25 
Size:	13.4 KB 
ID:	43653

    The Undo button undoes the record as it's supposed to, then locks all the buttons. I have no idea what's causing the buttons all to lock.
    Click image for larger version. 

Name:	Orgination Undo 2.JPG 
Views:	25 
Size:	33.0 KB 
ID:	43650

    Here's what's really strange. The only way I have found to escape is to right click on the form and select Close.
    Click image for larger version. 

Name:	Orgination Undo 3.JPG 
Views:	26 
Size:	20.9 KB 
ID:	43651
    When I do this, the form does not close, but the buttons are enabled. Which brings us back to doe.

    Click image for larger version. 

Name:	Orgination Undo 1a.JPG 
Views:	25 
Size:	39.5 KB 
ID:	43652

    Here's the code that runs when the Undo button is clicked.

    Code:
    Private Sub cmdUndo_Click()
    On Error GoTo Err_cmdUndo_Click
    If Me.Dirty Then
    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acUndo, , acMenuVer70
    End If
    Exit_cmdUndo_Click:
    Exit Sub
    Err_cmdUndo_Click:
    MsgBox Err.Description
    Resume Exit_cmdUndo_Click
    End Sub
    Oddly enough this code on the Exit button works fine.

    Code:
    Private Sub cmdExit_Click()
    On Error GoTo Err_cmdExit_Click
    If Me.Dirty Then
    If MsgBox("Do you wish to save this record?", vbYesNoCancel, "Save Record") = vbNo Then
    DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
    DoCmd.Close
    ElseIf IsNull(Me.Region) Then
    MsgBox "Please select a region."
    GoTo Exit_cmdExit_Click
    End If
    Else
    DoCmd.Close
    End If
    Exit_cmdExit_Click:
    Exit Sub
    Err_cmdExit_Click:
    MsgBox Err.Description
    Resume Exit_cmdExit_Click
    End Sub
    Private Sub

  2. #2
    Minty is online now VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,004
    Have you tried using

    Me.Undo

    ?
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    Paul H's Avatar
    Paul H is offline Expert
    Windows 10 Access 2016
    Join Date
    Sep 2011
    Location
    Richmond, VA
    Posts
    591
    Worked great.

    Here's another. I have a text box txtRegion on the form that is updated by combo box cboRegion in the AfterUpdate event. This works fine.

    Code:
    Private Sub cboRegion_AfterUpdate()
        txtRegion = Me.cboRegion.Column(1)
    End Sub

    The Undo button (which usually reverts cboRegion to it's original value) does not return txtRegion to its original value despite running the same code.
    txtRegion is for display purposes only. It is not bound to any field.

    Code:
    Private Sub cmdUndo_Click()
    On Error GoTo Err_cmdUndo_Click
    
    
        If Me.Dirty Then
            Me.Undo
            txtRegion = Me.cboRegion.Column(1)
        End If
    
    
    Exit_cmdUndo_Click:
            Exit Sub
    
    
    Err_cmdUndo_Click:
        MsgBox Err.Description
        Resume Exit_cmdUndo_Click
        Resume Next
    End Sub

  4. #4
    accesstos's Avatar
    accesstos is offline Expert
    Windows XP Access 2007
    Join Date
    Dec 2018
    Location
    Greece
    Posts
    551
    Quote Originally Posted by Paul H View Post
    txtRegion is for display purposes only. It is not bound to any field.
    So, use the Control Source of txtRegion rather than VBA: =[cboRegion].Column(1)
    But, why you don't display directly the second column of cboRegion?

  5. #5
    Paul H's Avatar
    Paul H is offline Expert
    Windows 10 Access 2016
    Join Date
    Sep 2011
    Location
    Richmond, VA
    Posts
    591
    =[cboRegion].Column(1) did the trick.

    The short answer to your question is that Region Name, the value of column 1, was not in the Recordsource for the form.
    Before I tried that I got your first suggestion to work so I am going to leave it at that.

    Thanks for your assistance.

    Paul

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

Similar Threads

  1. Activating Rubber duck VBA
    By Lou_Reed in forum Access
    Replies: 4
    Last Post: 01-14-2018, 10:00 AM

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