By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,107 Members | 1,318 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,107 IT Pros & Developers. It's quick & easy.

how to pass an old value field to another form

P: 27
Hello,

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

Expand|Select|Wrap|Line Numbers
  1. Private Sub Position_BeforeUpdate(Cancel As Integer)
  2.  
  3. Dim str As String
  4.     If Me.POSITION.OldValue <> Me.POSITION.value Then
  5.  
  6.             str = "INSERT INTO tbl_GCDS_Operations_Positions_fills " _
  7.                & "([REPLACEMENT FOR],[POSITION],[POSITION NAME],[Snr Dir],[UNIT],[REPLACEMENT LAST DATE],[CompanyStartDate],[Position Status]) VALUES " _
  8.                & "('" & Me![NAME] & "','" & Me![POSITION] & "','" & Me![POSITION] & "','" & Me![Reporting Level 1] & "','" & Me![Group] & "','" & Me![Leave Date] & "','" & Me![Company Start Date] & "','" & "Open" & "'); " _
  9.             'Debug.Print str
  10.             CurrentDb.Execute str
  11.     End If
  12.  
  13. End Sub
  14.  
Apr 30 '18 #1

✓ answered by twinnyfo

ivon,

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

Expand|Select|Wrap|Line Numbers
  1. Private Sub txtTest_Enter()
  2.     strText = Me.POSITION
  3. 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.

Share this Question
Share on Google+
1 Reply


twinnyfo
Expert Mod 2.5K+
P: 3,210
ivon,

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

Expand|Select|Wrap|Line Numbers
  1. Private Sub txtTest_Enter()
  2.     strText = Me.POSITION
  3. 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.
Apr 30 '18 #2

Post your reply

Sign in to post your reply or Sign up for a free account.