Results 1 to 12 of 12
  1. #1
    sra2786 is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Oct 2017
    Location
    Cincinnati, OH
    Posts
    38

    Undo not working on Combobox

    I have a form that updates a record in a table. The form has two comboboxes. Combobox #2 depends on Combobox #1. If I change the value in CB#1, CB#2 turns blank and you have to select a new value. If I then click on the UNDO button, CB#1 reverts to the original value but CB#2 reverts to blank and not the original value.



    CB#1 is based on a Value List
    CB#2 is based on a query.

    Undo Button logic
    Private Sub CmdUndo_Click()
    Me.Undo
    End Sub

    I have tried for hours to get this to work and I have had no luck. Based on everything I read, I should just be able to code "Me.Undo" and the data should revert to the original values.

    Any help would be greatly appreciated.
    Thanks.
    Sandy

  2. #2
    GinaWhipp's Avatar
    GinaWhipp is offline Competent Performer
    Windows 7 64bit Access 2013 32bit
    Join Date
    Jul 2011
    Location
    Ohio, USA
    Posts
    377
    Try....

    Code:
    Me.NameOfYourComboBox.Undo

  3. #3
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Combo boxes are usually meant to be unbound when used as a search function - especially if one depends on another one. Your code is attempting to undo record changes on the form but it's not clear to me if you're trying to revert selections in the combo(s). IMHO, undo isn't the way to go - if the combos are not bound, which as I'm saying, they shouldn't be.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    Code:
    Private Sub CmdUndo_Click()
        Me.Undo
        Call CB#1_AfterUpdate
    End Sub


    This should reestablish the value in cb#2 based on what's in cb#1
    This assumes you already have coded a cb#1_afterUpdate event.
    Last edited by davegri; 10-13-2018 at 09:55 PM. Reason: clarif

  5. #5
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Quote Originally Posted by Micron View Post
    Combo boxes are usually meant to be unbound when used as a search function - especially if one depends on another one. Your code is attempting to undo record changes on the form but it's not clear to me if you're trying to revert selections in the combo(s). IMHO, undo isn't the way to go - if the combos are not bound, which as I'm saying, they shouldn't be.
    Hi micron
    The last part is a masterclass in double negatives and perhaps contradicts the original point....possibly....its hard to be sure with two undo, 2 not and a shouldn't in the same sentence...
    Last edited by isladogs; 10-14-2018 at 08:53 AM.
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  6. #6
    sra2786 is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Oct 2017
    Location
    Cincinnati, OH
    Posts
    38
    This works if Column Width = 1";2" for CB#2. It does not work if Column Width = 0";2". I do not want the first column be the value that displays in the form because it is just an integer value. Any clever ideas how to make this work so the [Company-Name] value is displayed in the form. I am really new to Access so I do not have enough experience to be clever yet.

    CB#2 Properties
    Column Count = 2
    Column Width = 1";2"
    Control Source = field in the table
    Row Source Type = Table/Query
    Bound Column = 1
    Row Source =
    SELECT DISTINCT Value1, company & "-" & name AS [Company-Name]
    FROM tblTable1
    WHERE ( company = CB#1 );

    Thanks.
    Sandy

  7. #7
    GinaWhipp's Avatar
    GinaWhipp is offline Competent Performer
    Windows 7 64bit Access 2013 32bit
    Join Date
    Jul 2011
    Location
    Ohio, USA
    Posts
    377
    What is *this works*? In other words WHAT works when you show the Bound Column?

  8. #8
    sra2786 is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Oct 2017
    Location
    Cincinnati, OH
    Posts
    38
    What I mean by "this works" is the Undo shows the original value but the Combo Box how displays "key" value and not the text.

    For example, the Combo Box displays the value "21" instead of "Wendys - Type 21".

    I just don't understand why the UNDO works when Value1 (Bound column) is visible (Column Width = 1";2) and does not work when it is not visible (Column Width = 0";2").

    Value1 is included in the table assigned to the Record Souce of the Form. Is that the reason that it needs to be visible so UNDO will work?

  9. #9
    GinaWhipp's Avatar
    GinaWhipp is offline Competent Performer
    Windows 7 64bit Access 2013 32bit
    Join Date
    Jul 2011
    Location
    Ohio, USA
    Posts
    377
    It shouldn't matter so sounds like something else is going on. Do you have a Default set somewhere or is there something in your code in the On_Current event of the Form or something on one of the events of the Combo Box perhaps?

  10. #10
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    I just don't understand why the UNDO works when Value1 (Bound column) is visible (Column Width = 1";2) and does not work when it is not visible (Column Width = 0";2").
    Neither do I. Double check your work and make sure you are working with the right combobox.

  11. #11
    sra2786 is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Oct 2017
    Location
    Cincinnati, OH
    Posts
    38
    I got this to work finally. I had to add the line "Me.cbo2.Requery". Thank you to everyone who replied and said that it should work without setting Column Width = 0";2". I don't know why adding this line made the Undo start working but it did.


    Here is the final code
    Private Sub CmdUndo_Click()
    On Error GoTo ErrTrap


    Me.Undo
    Me.cbo2.Requery ' had to add this line

    ExitPoint:
    On Error GoTo 0
    Exit Sub

    ErrTrap:
    MsgBox Err.Number & " - " & Err.Description
    Resume ExitPoint
    End Sub

  12. #12
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Kinda what I was getting at in post 3, but it seemed to not go over very well.

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

Similar Threads

  1. Replies: 3
    Last Post: 04-16-2018, 03:20 AM
  2. Replies: 4
    Last Post: 08-27-2017, 08:21 AM
  3. combobox not working
    By LucLc in forum Access
    Replies: 4
    Last Post: 05-25-2016, 12:08 PM
  4. Combobox Query not working
    By ntaylor95814 in forum Forms
    Replies: 0
    Last Post: 04-15-2014, 04:29 PM
  5. vba code not working with combobox
    By bopsgtir in forum Programming
    Replies: 9
    Last Post: 02-24-2011, 11:27 AM

Tags for this Thread

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