Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Mar 2003
    Location
    Canton, Ohio, USA
    Posts
    103
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Entering repeated information (Win2000/Access2000)

    I have a form that users use to enter information into the database. A few of the fields, (like the date) are the same for a number of entries. Is there a way to set some of the fields in the form to not refresh after the form is entered. In other words, can I set some of the textboxes to always hold the last entered value until it is changed to something else?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Entering repeated information (Win2000/Access2000)


  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Entering repeated information (Win2000/Access2000)

    Another method is to use the AfterUpdate event of the form to set the default value of the controls you want to carry forward. The code might look something like the following. Remember that this is air code, but I use this technique daily, so I know it works. This has no effect on existing records, only new records.

    <pre>' Put this in the form's Declarations
    Dim mfCarryForward As Boolean

    Private Sub Form_BeforeUpdate(Cancel As Integer)
    ' Set the module level flag to trigger resetting the
    ' default values if this is a new record

    mfCarryForward = (Me.NewRecord = True)
    End Sub

    Private Sub Form_AfterUpdate()
    Dim intLoop As Integer
    Dim ctl As Control
    ' Set this constant to the number of controls you want to carry forward
    Const NUMCTLS As Integer = 5

    ' Loop through the controls if mfCarryForward is True
    If mfCarryForward Then
    For intLoop = 1 To NUMCTLS

    ' Set an object pointer to each control in turn
    Set ctl = Me(Choose(intLoop, "Text0", "Text1", "Text2", "Text3", "Text4"))

    ' If the control value has changed from the default
    ' reset the default value to the new control value so it will
    ' carry forward to the next new record

    If ctl.DefaultValue <> ctl.Value Then
    ctl.DefaultValue = ctl.Value
    End If
    Next intLoop
    End If

    Form_AfterUpdate_Exit:
    On Error Resume Next
    Set ctl = Nothing
    End Sub</pre>

    Charlotte

  4. #4
    2 Star Lounger
    Join Date
    Mar 2003
    Location
    Canton, Ohio, USA
    Posts
    103
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Entering repeated information (Win2000/Access2000)

    Thanks Charlotte, Your way seems easier but I haven't got it to work yet. Are the only changes I need to make to "Text 0", "Text 1, .... to the names of my fields. Like txtDate, txtSession,...?

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Entering repeated information (Win2000/Access2000)

    You need to set the value of NUMCTLS to the number of controls you want to carry forward, and to replace Text0 etc. by the names of your controls. Add or remove to get the correct number of fields.

    Charlotte's code will work for number, currency and date/time fields, but not "as is" for text fields. If you only want to carry forward text fields, change the line

    ctl.DefaultValue = ctl.Value

    to

    ctl.DefaultValue = Chr(34) & ctl.Value & Chr(34)

    If you want a mix of text and other fields, the code needs more work.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •