Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2005
    Posts
    23

    Unanswered: Combo Box : Revert to original value

    PROBLEM:

    I have a combo box on a form and I am having trouble having the combo box resort to it's original value after exiting the routine.


    For example, let's say the combo box has two values "1" and "2".

    The combo box is set to "1". It is changed to "2". Then the After Update code executes and fires off the yes/no message box. The result of the message box is "no" and the code exits the routine. I am now left with "2" in the combo box.

    After the "no" and subsequent exit I would like the combo box to revert back to its originall entry of "1".

    ------------------------
    MY ATTEMPTED SOLUTION

    I tried to hold a global variable on the before update event on the combo box to trap the original value and then add it before the exit in the after update "no" event.

    Below is my code
    ---------------------------
    Option Compare Database
    Option Explicit

    Private xValueForType As String
    ----------------------------------------------------------------
    Private Sub cmbTypeForSize_BeforeUpdate(Cancel As Integer)

    xValueForType = Me!XADDED_TypeForSize

    End Sub
    -----------------------------------------------------------------
    Private Sub cmbTypeForSize_AfterUpdate()

    Dim xResponse

    xResponse = MsgBox("Are you sure you want to change this value?" & vbCrLf & _
    "This will clear all input for the Product.", vbYesNo + vbCritical)

    If xResponse = vbYes Then
    GoTo Proceed01

    Else
    Me.cmbTypeForSize.Value = xValueForType

    Exit Sub

    End If

  2. #2
    Join Date
    Oct 2005
    Posts
    183
    After you set your value on the combobox, you might need an update of the visible value. Me.Refresh perhaps.

    If you do a msgbox "fsdfdsfsdf the value is now " & Me.cmbTypeForSize.Value & "", vbinformation you will most likely find the value to your satisfaction. However, the Me.cmbTypeForSize.Value = 1 wont make the value visible, that is, update the screen.

    So try a Me.Refresh for starters or a Me.cmbTypeForSize.refresh

    Cheers, Trin

  3. #3
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    the old value should be available in the control.oldvalue property (depending on the version of Access you are using), which you cna retrieve in the forms after update event

  4. #4
    Join Date
    Oct 2005
    Posts
    183
    You may also need to do a requery on the combobox object...

  5. #5
    Join Date
    Aug 2005
    Posts
    23

    Thumbs up It worked!

    Quote Originally Posted by healdem
    the old value should be available in the control.oldvalue property (depending on the version of Access you are using), which you cna retrieve in the forms after update event
    Thanks. I am using Access 2000 and the control.oldvalue worked like a charm.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •