Results 1 to 7 of 7
  1. #1
    2 Star Lounger
    Join Date
    Jul 2003
    Location
    Cincinnati, Ohio
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Duplicate specific fields (2003)

    I have a form (frmMeetings) that contains serveral fields that I would like to be able to duplicate onto a new record (meetingname, meetingpurpose, attendees, region, etc.) for the times that the meeting repeats. I would like to copy only those fields onto a new record so the duplicate function does not appear to be an option unless it can be restricted to only those fields. Can this be done/how would I go about it? Thank you for your help. - Scott

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

  3. #3
    2 Star Lounger
    Join Date
    Jul 2003
    Location
    Cincinnati, Ohio
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Duplicate specific fields (2003)

    (Edited by HansV to make URL clickable - see <!help=19>Help 19<!/help>)

    Hans, Thank you for the KB reference. The solution calls a procedure from the OnCurrent event on the form. Is there a way to optionally invoke this functionality? Ideally I would like to attach this to a button/OnClick event on the form so I could chose if I wanted to duplicate the specified fields on a new record? I tried putting after DoCmd.GoToRecord , , acNewRec with no luck.

    Also, if it helps anyone I found a web site with a list of Access KB articles: http://www.kayodeok.btinternet.co.uk/favor...accesshowto.htm Thanks again.

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

    Re: Duplicate specific fields (2003)

    You should be able to use code like this:

    Private Sub cmdDuplicate_Click()
    If Not IsNull(Me.ID) Then
    RunCommand acCmdRecordsGoToNew
    Call AutoFillNewRecord(Me)
    End If
    End Sub

    Replace ID with the name of the unique ID of the record. And don't use the function in the On Current event of the form!

  5. #5
    2 Star Lounger
    Join Date
    Jul 2003
    Location
    Cincinnati, Ohio
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Duplicate specific fields (2003)

    The replication works but from the last record. Is there a way for this work with the current record? Thanks.

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

    Re: Duplicate specific fields (2003)

    Change the function as follows:

    Function AutoFillNewRecord(F As Form)
    Dim RS As DAO.Recordset, C As Control
    Dim FillFields As String, FillAllFields As Integer

    On Error Resume Next

    ' Goto the current record of the form recordset (to autofill form).
    Set RS = F.RecordsetClone
    RS.Bookmark = F.Bookmark

    ' Exit if error occurred.
    If Err <> 0 Then Exit Function

    ' Get the list of fields to autofill.
    FillFields = ";" & F!<!t>[AutoFillNewRecordFields]<!/t> & ";"

    ' If there is no criteria field, then set flag indicating ALL
    ' fields should be autofilled.
    FillAllFields = Err <> 0

    RunCommand acCmdRecordsGoToNew
    F.Painting = False

    ' Visit each field on the form.
    For Each C In F
    ' Fill the field if ALL fields are to be filled OR if the
    ' ...ControlSource field can be found in the FillFields list.
    If FillAllFields Or InStr(FillFields, ";" & (C.Name) & ";") > 0 Then
    C = RS(C.ControlSource)
    End If
    Next

    F.Painting = True
    End Function

    Remove the line to move to a new record from the On Click event procedure of the command button - the function now takes care of that.

  7. #7
    2 Star Lounger
    Join Date
    Jul 2003
    Location
    Cincinnati, Ohio
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Duplicate specific fields (2003)

    That works perfectly. Thank you Hans.

Posting Permissions

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