RecordsetClone to copy a record/referencing other forms

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I to duplicate a record (everything but the key field). If I use the
following code for my button in the form that I am duplicating, then it works:

If Me.NewRecord Then
MsgBox "You are on a new record." & _
"Select the record to duplicate."

Else
With Me.RecordsetClone
.AddNew
![JWO_Date of Order] = Me.[JWO_Date of Order]
![JWO_Job Type] = Me.[JWO_Job Type]
![JWO_Customer's Order Number] = Me.[JWO_Customer's Order Number]
![JWO_Subcontract Number] = Me.[JWO_Subcontract Number]
![JWO_Customer] = Me.[JWO_Customer]
![CU_Customer Address] = Me.[CU_Customer Address]
![CU_Customer City] = Me.[CU_Customer City]
![CU_Customer State] = Me.[CU_Customer State]
![CU_Customer Postal Code] = Me.[CU_Customer Postal Code]
![CU_Customer Phone Number] = Me.[CU_Customer Phone Number]
![CU_Customer Fax Number] = Me.[CU_Customer Fax Number]
![JWO_Contact] = Me.[JWO_Contact]
![JWO_Project Manager] = Me.[JWO_Project Manager]
![PM_Cell Phone Number] = Me.[PM_Cell Phone Number]
![PM_E-Mail Address] = Me.[PM_E-Mail Address]
![JWO_Project Superintendent] = Me.[JWO_Project Superintendent]
![JS_Cell Phone Number] = Me.[JS_Cell Phone Number]
![JWO_Project Name] = Me.[JWO_Project Name]
![PJ_Address] = Me.[PJ_Address]
![PJ_City] = Me.[PJ_City]
![PJ_County] = Me.[PJ_County]
![PJ_State] = Me.[PJ_State]
![PJ_Postal Code] = Me.[PJ_Postal Code]

.Update
End With
DoCmd.GoToRecord , , acLast
End If

However, I want to do it from a button in a DIFFERENT form so I added this
code to the beginning:

Forms("Job Work Orders Form").SetFocus

But I get an error:

You entered an expression that has an invalid reference to the
RecordsetClone property.

How do I get the code to reference the main form so that it will work?
 
First, a clarifying question....

You want to run this code in the second form. But are you adding the
duplicated data to that second form's recordset, or to the first form's
recordset? And which form has the data record that is being used to make the
duplicate?
 
Sorry for the confusion.

The first form is the main form. The second form is strictly buttons (like
a toolbar). All of the work or data is entered into the first form. If
someone wants to print, search, delete, etc. a record in the first form, they
click a button in the second.

So in this instance, if there is a job that is almost exactly like one
previously entered in the first form, I want to be able to duplicate that
record in that form by clicking a button in the second.

Clear as mud?

Ken Snell (MVP) said:
First, a clarifying question....

You want to run this code in the second form. But are you adding the
duplicated data to that second form's recordset, or to the first form's
recordset? And which form has the data record that is being used to make the
duplicate?
--

Ken Snell
<MS ACCESS MVP>



Christian > said:
I to duplicate a record (everything but the key field). If I use the
following code for my button in the form that I am duplicating, then it
works:

If Me.NewRecord Then
MsgBox "You are on a new record." & _
"Select the record to duplicate."

Else
With Me.RecordsetClone
.AddNew
![JWO_Date of Order] = Me.[JWO_Date of Order]
![JWO_Job Type] = Me.[JWO_Job Type]
![JWO_Customer's Order Number] = Me.[JWO_Customer's Order
Number]
![JWO_Subcontract Number] = Me.[JWO_Subcontract Number]
![JWO_Customer] = Me.[JWO_Customer]
![CU_Customer Address] = Me.[CU_Customer Address]
![CU_Customer City] = Me.[CU_Customer City]
![CU_Customer State] = Me.[CU_Customer State]
![CU_Customer Postal Code] = Me.[CU_Customer Postal Code]
![CU_Customer Phone Number] = Me.[CU_Customer Phone Number]
![CU_Customer Fax Number] = Me.[CU_Customer Fax Number]
![JWO_Contact] = Me.[JWO_Contact]
![JWO_Project Manager] = Me.[JWO_Project Manager]
![PM_Cell Phone Number] = Me.[PM_Cell Phone Number]
![PM_E-Mail Address] = Me.[PM_E-Mail Address]
![JWO_Project Superintendent] = Me.[JWO_Project Superintendent]
![JS_Cell Phone Number] = Me.[JS_Cell Phone Number]
![JWO_Project Name] = Me.[JWO_Project Name]
![PJ_Address] = Me.[PJ_Address]
![PJ_City] = Me.[PJ_City]
![PJ_County] = Me.[PJ_County]
![PJ_State] = Me.[PJ_State]
![PJ_Postal Code] = Me.[PJ_Postal Code]

.Update
End With
DoCmd.GoToRecord , , acLast
End If

However, I want to do it from a button in a DIFFERENT form so I added this
code to the beginning:

Forms("Job Work Orders Form").SetFocus

But I get an error:

You entered an expression that has an invalid reference to the
RecordsetClone property.

How do I get the code to reference the main form so that it will work?
 
Christian said:
I to duplicate a record (everything but the key field). If I use the
following code for my button in the form that I am duplicating, then it works:

If Me.NewRecord Then
MsgBox "You are on a new record." & _
"Select the record to duplicate."

Else
With Me.RecordsetClone
.AddNew
![JWO_Date of Order] = Me.[JWO_Date of Order]
![JWO_Job Type] = Me.[JWO_Job Type]
![JWO_Customer's Order Number] = Me.[JWO_Customer's Order Number]
![JWO_Subcontract Number] = Me.[JWO_Subcontract Number]
![JWO_Customer] = Me.[JWO_Customer]
![CU_Customer Address] = Me.[CU_Customer Address]
![CU_Customer City] = Me.[CU_Customer City]
![CU_Customer State] = Me.[CU_Customer State]
![CU_Customer Postal Code] = Me.[CU_Customer Postal Code]
![CU_Customer Phone Number] = Me.[CU_Customer Phone Number]
![CU_Customer Fax Number] = Me.[CU_Customer Fax Number]
![JWO_Contact] = Me.[JWO_Contact]
![JWO_Project Manager] = Me.[JWO_Project Manager]
![PM_Cell Phone Number] = Me.[PM_Cell Phone Number]
![PM_E-Mail Address] = Me.[PM_E-Mail Address]
![JWO_Project Superintendent] = Me.[JWO_Project Superintendent]
![JS_Cell Phone Number] = Me.[JS_Cell Phone Number]
![JWO_Project Name] = Me.[JWO_Project Name]
![PJ_Address] = Me.[PJ_Address]
![PJ_City] = Me.[PJ_City]
![PJ_County] = Me.[PJ_County]
![PJ_State] = Me.[PJ_State]
![PJ_Postal Code] = Me.[PJ_Postal Code]

.Update
End With
DoCmd.GoToRecord , , acLast
End If

However, I want to do it from a button in a DIFFERENT form so I added this
code to the beginning:

Forms("Job Work Orders Form").SetFocus

But I get an error:

You entered an expression that has an invalid reference to the
RecordsetClone property.

How do I get the code to reference the main form so that it will work?


You must replace all references to Me with a reference to
the form you are operating on.

Dim frm As Form
Set frm = Forms("Job Work Orders Form")

If frm.NewRecord Then
MsgBox "You are on a new record." & _
"Select the record to duplicate."

Else
With frm.RecordsetClone
.AddNew
![JWO_Date of Order] = frm.[JWO_Date of Order]
. . .
 
That did it. THANKS SO MUCH!!!!!

Marshall Barton said:
Christian said:
I to duplicate a record (everything but the key field). If I use the
following code for my button in the form that I am duplicating, then it works:

If Me.NewRecord Then
MsgBox "You are on a new record." & _
"Select the record to duplicate."

Else
With Me.RecordsetClone
.AddNew
![JWO_Date of Order] = Me.[JWO_Date of Order]
![JWO_Job Type] = Me.[JWO_Job Type]
![JWO_Customer's Order Number] = Me.[JWO_Customer's Order Number]
![JWO_Subcontract Number] = Me.[JWO_Subcontract Number]
![JWO_Customer] = Me.[JWO_Customer]
![CU_Customer Address] = Me.[CU_Customer Address]
![CU_Customer City] = Me.[CU_Customer City]
![CU_Customer State] = Me.[CU_Customer State]
![CU_Customer Postal Code] = Me.[CU_Customer Postal Code]
![CU_Customer Phone Number] = Me.[CU_Customer Phone Number]
![CU_Customer Fax Number] = Me.[CU_Customer Fax Number]
![JWO_Contact] = Me.[JWO_Contact]
![JWO_Project Manager] = Me.[JWO_Project Manager]
![PM_Cell Phone Number] = Me.[PM_Cell Phone Number]
![PM_E-Mail Address] = Me.[PM_E-Mail Address]
![JWO_Project Superintendent] = Me.[JWO_Project Superintendent]
![JS_Cell Phone Number] = Me.[JS_Cell Phone Number]
![JWO_Project Name] = Me.[JWO_Project Name]
![PJ_Address] = Me.[PJ_Address]
![PJ_City] = Me.[PJ_City]
![PJ_County] = Me.[PJ_County]
![PJ_State] = Me.[PJ_State]
![PJ_Postal Code] = Me.[PJ_Postal Code]

.Update
End With
DoCmd.GoToRecord , , acLast
End If

However, I want to do it from a button in a DIFFERENT form so I added this
code to the beginning:

Forms("Job Work Orders Form").SetFocus

But I get an error:

You entered an expression that has an invalid reference to the
RecordsetClone property.

How do I get the code to reference the main form so that it will work?


You must replace all references to Me with a reference to
the form you are operating on.

Dim frm As Form
Set frm = Forms("Job Work Orders Form")

If frm.NewRecord Then
MsgBox "You are on a new record." & _
"Select the record to duplicate."

Else
With frm.RecordsetClone
.AddNew
![JWO_Date of Order] = frm.[JWO_Date of Order]
. . .
 
Back
Top