Value of from Combo Box before update

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • reginaldmerritt
    New Member
    • Nov 2006
    • 201

    Value of from Combo Box before update

    I'm trying to get the value of a combobox before an update. I've tried using before update and onclick, but these stil show the value after the update rather than the original value before the update?

    For example the code below will show the new changed value of the combobox and never thw value before the change\upadate

    Code:
    Private Sub ControlCombobox1_AfterUpdate()
    If Not IsNull(ControlCombobox1) And ControlCombobox1 <> "" Then
       MsgBox ("[AfterUpdate] Value:" & ControlCombobox1)
    End If
    End Sub
    
    Private Sub ControlCombobox1_BeforeUpdate(Cancel As Integer)
    If Not IsNull(ControlCombobox1) And ControlCombobox1 <> "" Then
       MsgBox ("[BeforeUpdate] Value:" & ControlCombobox1)
    End If
    End Sub
    
    Private Sub ControlCombobox1_Click()
    If Not IsNull(ControlCombobox1) And ControlCombobox1 <> "" Then
       MsgBox ("[OnClick] Value:" & ControlCombobox1)
    End If
    End Sub
  • missinglinq
    Recognized Expert Specialist
    • Nov 2006
    • 3533

    #2
    ControlCombobox 1.OldValue should give you the previous value.

    Linq ;0)>

    Comment

    • reginaldmerritt
      New Member
      • Nov 2006
      • 201

      #3
      ControlCombobox 1.OldValue sounds great but still gives the new value

      Code:
      Private Sub ControlCombobox1_AfterUpdate()
      If Not IsNull(ControlCombobox1) And ControlCombobox1 <> "" Then
          MsgBox ("[AfterUpdate] Value:" & ControlCombobox1)
          MsgBox ("[AfterUpdate] Old Value:" & ControlCombobox1.OldValue)
      End If
      End Sub
      both msgboxes give me the new value and never the previous value?

      same thing happens if i put the message boxes under Onclick and BeforeUpdate events.

      i'm confussed.com

      Comment

      • missinglinq
        Recognized Expert Specialist
        • Nov 2006
        • 3533

        #4
        My guess would be that your ControlCombobx1 control is not bound to a field in the underlying table, which means that it doesn't have an OldValue. This is the only way I can replicate your results.

        Exactly what are you trying to accomplish here?

        Linq ;0)>

        Comment

        • reginaldmerritt
          New Member
          • Nov 2006
          • 201

          #5
          I was afraid you would ask that as it's a bit long winded, but i'll try to make it as clear and possible.

          the control is bound to a field on my main program but not on the test code i used above.

          When i use .OldValue on my main code it gets very complicted. The .OldValue works once but then stops working. Basicaly .OldValue seems hold the value when the form is loaded and does not change when i change the combobox value.

          I have a table tbInvoices which i use a combobox control on a field in tbInvoices which allows me to add a product number to the invoice which i taken from tbCRB. Apone adding the product to the invoice i have a recordset that writes to tbCRB to mark the product as having been added to an invoice.

          When i then change the product to a different product i want to mark the previous product as nolonger beeing added to an invoice so that it can be used again.

          These products can only be used once and added to an invoice once.

          sorry it's a bit difficult to explaine.

          Comment

          • reginaldmerritt
            New Member
            • Nov 2006
            • 201

            #6
            Does anyone know of another way of grapping the previous value other than .OldValue.

            I guess i could create an array to hold values of the combobox on load and afterupdate.

            Comment

            • reginaldmerritt
              New Member
              • Nov 2006
              • 201

              #7
              As i couldn't find another way of getting hold of a cobobox previous value i had to create an array to hold the values after update so i could use these values to compare with any future updates.

              Had some problems will array holding null values but i got around this by not checking for null values, instead I check the length of the sting in the array.

              Code:
              Private Sub UpdatePreviousFormNumberArray()
              Dim CounterA, CounterB As Integer
              Dim CurrentFormNumberLENGTH
              CounterA = 0
              For CounterA = 1 To 10
                  CurrentFormNumberLENGTH = Len(Me.Controls("AppFrmNum" & CounterA))
                  If CurrentFormNumberLENGTH > 0 Then
                      PreviousFormNumber(CounterA) = Me.Controls("AppFrmNum" & CounterA)
                  End If
                  If CurrentFormNumberLENGTH = 0 Then
                      PreviousFormNumber(CounterA) = ""
                  End If
              Next
              'MsgBox ("--------- Form Number Array Updated ---------" & vbNewLine & "[01] " & PreviousFormNumber(1) & vbNewLine & "[02] " & PreviousFormNumber(2) & vbNewLine & "[03] " & PreviousFormNumber(3) & vbNewLine & "[04] " & PreviousFormNumber(4) & vbNewLine & "[05] " & PreviousFormNumber(5) & vbNewLine & "[06] " & PreviousFormNumber(6) & vbNewLine & "[07] " & PreviousFormNumber(7) & vbNewLine & "[08] " & PreviousFormNumber(8) & vbNewLine & "[09] " & PreviousFormNumber(9) & vbNewLine & "[10] " & PreviousFormNumber(10))
              End Sub
              
              Private Sub MarkAsAdded()
              PreviousFormNumberLENGTH = Len(PreviousFormNumber(LineNumber))
              Thanks for your help missinglinq.

              Comment

              Working...