how to pass an old value field to another form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ivonsurf123
    New Member
    • Nov 2017
    • 27

    how to pass an old value field to another form

    Hello,

    Could you help me please? I have a problem with a if sentence and a query: I need to pass the POSITION.OldVal ue to another form but it is getting the new value instead.Thank you.

    Code:
    Private Sub Position_BeforeUpdate(Cancel As Integer)
    
    Dim str As String
        If Me.POSITION.OldValue <> Me.POSITION.value Then
                  
                str = "INSERT INTO tbl_GCDS_Operations_Positions_fills " _
                   & "([REPLACEMENT FOR],[POSITION],[POSITION NAME],[Snr Dir],[UNIT],[REPLACEMENT LAST DATE],[CompanyStartDate],[Position Status]) VALUES " _
                   & "('" & Me![NAME] & "','" & Me![POSITION] & "','" & Me![POSITION] & "','" & Me![Reporting Level 1] & "','" & Me![Group] & "','" & Me![Leave Date] & "','" & Me![Company Start Date] & "','" & "Open" & "'); " _
                'Debug.Print str
                CurrentDb.Execute str
        End If
    
    End Sub
  • twinnyfo
    Recognized Expert Moderator Specialist
    • Nov 2011
    • 3653

    #2
    ivon,

    I would declare a form-specific variable strText, and then in the OnEnter Event, add similar code like this:

    Code:
    Private Sub txtTest_Enter()
        strText = Me.POSITION
    End Sub
    Then, use that variable as the "Old Value".

    Keep in mind that it looks like you may have simply named a text box the same name as the underlying field. In which case, Access will automatically default to the value of the underlying field and not the value in the control on the Form. This is why I encourage all folks to use a good naming convention with their controls.

    Hope this hepps.

    Comment

    Working...