Copy Record Button Function

  • Thread starter Stacey Crowhurst
  • Start date
S

Stacey Crowhurst

Hi. I have two forms that I would like to add a copy record button to. But
I get error messages [Run-time error 3414] when I try. It points to this
line of code when I click debug: If Not rs.EOF Then Me.Bookmark = rs.Bookmark

After troubleshooting for a bit, I realized that both forms have lookup
boxes in the form header section. If I delete the lookup box from the form I
can add a duplicate record button without a problem. Is there anyway to have
both the lookup box and the duplicate record button on the form
simulatneously?

Here is the code for one of the lookup boxes (from the wizard)

Private Sub lkpCostCode_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[cocCostCodeID] = '" & Me![lkpCostCode] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub

Let me know if you need more information or have questions.

Thank you in advance !!! :)

Stacey
 
M

Marshall Barton

Stacey said:
Hi. I have two forms that I would like to add a copy record button to. But
I get error messages [Run-time error 3414] when I try. It points to this
line of code when I click debug: If Not rs.EOF Then Me.Bookmark = rs.Bookmark

After troubleshooting for a bit, I realized that both forms have lookup
boxes in the form header section. If I delete the lookup box from the form I
can add a duplicate record button without a problem. Is there anyway to have
both the lookup box and the duplicate record button on the form
simulatneously?

Here is the code for one of the lookup boxes (from the wizard)

Private Sub lkpCostCode_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[cocCostCodeID] = '" & Me![lkpCostCode] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub

Inspite of it being generated by a wizard, the code is
wrong. It should be more like:

Private Sub lkpCostCode_AfterUpdate()
' Find the record that matches the control.
With Me.RecordsetClone
.FindFirst "cocCostCodeID = '" & Me!lkpCostCode & "' "
If Not NoMatch Then
Me.Bookmark = .Bookmark
Else
Beep
End If
End With
End Sub

I think another problen that is causing the lookup to get in
trouble is that you are also using a wizard's code to copy a
record. The Copy Record wizard's code is very weak an only
works in the simplest situations, In you case, it appears
to be copying the combo box's value even though it is
unbound and not a field in the form's record source. A far
safer and more discrimating way to copy only the fields that
need to be copied is to use something similar to:

With Me.RecordsetClone
.AddNew
!thisfield = Me.thisfield
!thatfield = Me.thatfield
. . .
.Update
Me.Bookmark = .LastModified
End With
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top