Results 1 to 4 of 4
  1. #1
    cshort64 is offline Novice
    Windows XP Access 2007
    Join Date
    Nov 2011
    Posts
    2

    Help copying field values within a form

    I want to keep history of a change on one field. I only need to keep the last change.

    Example I have two fields CurrentSerialNum and OldSerialNum. If a change is made to CurrentSerialNumb on the form I want to copy the value of CurrentSerialNum (prior to the change) to OldSerialNum.

    I have added the following code to onclick and onupdate sections of CurrentSerialNum however on updating the CurrentSerialNum field OldSerialNum is updated to null. Any idea on what I am doing wrong?

    Private Sub CurrentSeriealNum_AfterUpdate()
    me.OldSerialNum.Value = mCurrentSerialNum
    End Sub

    Public Sub CurrentSeriealNum_Click()
    Dim mCurrentSerialNum As String
    mCurrentSerialNum = me.CurrentSeriealNum
    End Sub
    Last edited by cshort64; 11-11-2011 at 10:18 AM. Reason: Correct cut and paste error

  2. #2
    Toyman is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Posts
    233
    Quote Originally Posted by cshort64 View Post
    I want to keep history of a change on one field. I only need to keep the last change

    Example I have two fields CurrentSerialNumber and OldSerialNumber. If a change is made to CurrentSerialNumber on the form I want to copy the value of CurrentSerialNumber prior to the change to OldSerialNumber.

    I have added the following code to onclick and onupdate sections of CurrentSerialNum however on updating the CurrentSerialNum field OldSerialNum is updated to null. Any idea on what I am doing wrong.

    Private Sub CurrentSeriealNum_AfterUpdate()
    me.OldSerialNum.Value = mCurrentSerialNum
    End Sub

    Public Sub CurrentCalibratorSeal_Click()
    Dim mCurrentSerialNum As String
    mCurrentSerialNum = Me.CurrentSeriealNum
    End Sub
    You need to put the code in the "on enter" event:
    Dim mCurrentSerialNum As String
    mCurrentSerialNum = Me.CurrentSeriealNum

  3. #3
    cshort64 is offline Novice
    Windows XP Access 2007
    Join Date
    Nov 2011
    Posts
    2
    Thanks Toyman,

    I tried that and have the same results. Do I need to pass the variable to the onupdate process?

  4. #4
    Toyman is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Posts
    233
    Quote Originally Posted by cshort64 View Post
    Thanks Toyman,

    I tried that and have the same results. Do I need to pass the variable to the onupdate process?
    make sure your veriable, "mCurrentSerialNum" is decleared for the form and not just the current procedure. To do that, you need to declear it at the top of the vb window, right below "Option Compare Database"

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

Similar Threads

  1. Replies: 1
    Last Post: 11-01-2011, 05:55 PM
  2. Copying Values from One Record to Another
    By Iconoclast in forum Access
    Replies: 5
    Last Post: 08-02-2011, 11:59 AM
  3. Replies: 6
    Last Post: 03-22-2011, 08:22 PM
  4. Replies: 0
    Last Post: 07-16-2010, 09:06 AM
  5. Copying only part of data from a text field
    By davedejonge in forum Queries
    Replies: 1
    Last Post: 02-03-2010, 05:18 PM

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