Copying information to next record

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • CleverOne
    New Member
    • Jul 2007
    • 2

    Copying information to next record

    Hi i have a text box that i want to copy whatever i have in it to the next record in the same textbox and this is all determined if the checkbox next to it is checked.
    I have the following code for it so far but its not working.

    Private Sub txtTRKNUM_After Update()
    If chkTRACKLOCK.Va lue = Checked Then
    txtTRKNUM.Defau ltValue = txtTRKNUM
    End If
    End Sub

    Is this the approach i should take?
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Originally posted by CleverOne
    Hi i have a text box that i want to copy whatever i have in it to the next record in the same textbox and this is all determined if the checkbox next to it is checked.
    I have the following code for it so far but its not working.

    Private Sub txtTRKNUM_After Update()
    If chkTRACKLOCK.Va lue = Checked Then
    txtTRKNUM.Defau ltValue = txtTRKNUM
    End If
    End Sub

    Is this the approach i should take?
    [CODE=vb]
    Private Sub txtTRKNUM_After Update()
    If Not IsNull(Me![txtTRKNUM]) And Me![chkTRACKLOCK] = True Then
    Me![txtTRKNUM].DefaultValue = "'" & Me![txtTRKNUM] & "'"
    End If
    End Sub
    [/CODE]

    Comment

    • missinglinq
      Recognized Expert Specialist
      • Nov 2006
      • 3533

      #3
      ADezii's code will work, but I see a possible problem here, in that Me![txtTRKNUM] will continue to have a default value, whether the box is checked or not, in some circumstances, i.e.

      Record A
      Me![txtTRKNUM] = "123"
      [chkTRACKLOCK] = True
      Me![txtTRKNUM].DefaultValue = "123"

      Record B
      Me![txtTRKNUM] = "123"
      [chkTRACKLOCK] = False
      Me![txtTRKNUM].DefaultValue will still be "123" and carried forward

      Record C
      Me![txtTRKNUM] = "123" because the default value is still "123" and will continue to be, until a new value is entered for [txtTRKNUM] and made the default by checking [chkTRACKLOCK] or until the form is closed.

      Perhaps an Else statement is in order, setting the default to an empty string if the checkbox is unchecked:
      [CODE=vb]Private Sub txtTRKNUM_After Update()
      If Not IsNull(Me![txtTRKNUM]) And Me![chkTRACKLOCK] = True Then
      Me![txtTRKNUM].DefaultValue = "'" & Me![txtTRKNUM] & "'"
      Else
      Me![txtTRKNUM].DefaultValue = " "
      End If
      End Sub[/CODE]Welcome to TheScripts!

      Linq ;0)>

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        Originally posted by missinglinq
        ADezii's code will work, but I see a possible problem here, in that Me![txtTRKNUM] will continue to have a default value, whether the box is checked or not, in some circumstances, i.e.

        Record A
        Me![txtTRKNUM] = "123"
        [chkTRACKLOCK] = True
        Me![txtTRKNUM].DefaultValue = "123"

        Record B
        Me![txtTRKNUM] = "123"
        [chkTRACKLOCK] = False
        Me![txtTRKNUM].DefaultValue will still be "123" and carried forward

        Record C
        Me![txtTRKNUM] = "123" because the default value is still "123" and will continue to be, until a new value is entered for [txtTRKNUM] and made the default by checking [chkTRACKLOCK] or until the form is closed.

        Perhaps an Else statement is in order, setting the default to an empty string if the checkbox is unchecked:
        [CODE=vb]Private Sub txtTRKNUM_After Update()
        If Not IsNull(Me![txtTRKNUM]) And Me![chkTRACKLOCK] = True Then
        Me![txtTRKNUM].DefaultValue = "'" & Me![txtTRKNUM] & "'"
        Else
        Me![txtTRKNUM].DefaultValue = " "
        End If
        End Sub[/CODE]Welcome to TheScripts!

        Linq ;0)>
        Good point, ling. I'll redirect the OP to reference your Post. Thanks.

        Comment

        • ADezii
          Recognized Expert Expert
          • Apr 2006
          • 8834

          #5
          Originally posted by CleverOne
          Hi i have a text box that i want to copy whatever i have in it to the next record in the same textbox and this is all determined if the checkbox next to it is checked.
          I have the following code for it so far but its not working.

          Private Sub txtTRKNUM_After Update()
          If chkTRACKLOCK.Va lue = Checked Then
          txtTRKNUM.Defau ltValue = txtTRKNUM
          End If
          End Sub

          Is this the approach i should take?
          See Post #3 by missingling for the correct approach.

          Comment

          Working...