Duplicate Fields

stauartadair

Registered User.
Local time
Today, 06:54
Joined
Sep 28, 2007
Messages
12
I've got a simple form operating on a database with a duplicate record button at the bottom. When the butten is clicked I want to create a new record with only some of the fields carried forward from the previous record.
Duplicate function copies all fields.
Is there a way to do this ?

Stu
 
Below is a generic version of code that I use to accomplish this. As my signature insinuates, this is only one of several ways to do the job! Good luck!

'Copy fields from original record to variables
NewField1 = Me.YourField1
NewField2 = Me.YourField2
NewField3 = Me.YourField3

'Go to a new record
DoCmd.GoToRecord , , acNewRec

'Plug in old values into new record
Me.YourField1.Value = NewField1
Me.YourField2.Value = NewField2
Me.YourField3.Value = NewField3
 
I am an newby to access and am trying to prefill new records with the previouse records values. From what I understand, I need to follow these
steps. Please let me know where I am going wrong or what I am missing, because it does not work.

1. Open Form in Design View
2. Click property sheet.
3. Selection type is Form
4. On Current
[Event Procedure]
[...]

** Copy fields from original record to variables
SalesOrder1 = Me.SalesOrder

*** Go to a new record
DoCmd.GoToRecord , , acNewRec

*** Plug in old values into new record
Me.SalesOrder.Value = SalesOrder1

Thank You for any help you can give. :confused:
 
Place the code behind the "duplicate" button (in the button's click event) you said you already had on your form! If the button were called CopyToNewRecord the code would be:

Code:
Private Sub CopyToNewRecord_Click()
'Copy fields from original record to variables
NewField1 = Me.YourField1
NewField2 = Me.YourField2
NewField3 = Me.YourField3

'Go to a new record
DoCmd.GoToRecord , , acNewRec

'Plug in old values into new record
Me.YourField1.Value = NewField1
Me.YourField2.Value = NewField2
Me.YourField3.Value = NewField3
End Sub
 
Wazz

I tried what the link said to do and the next records value is still null

Here are my event procedures. I am assuming both events are stored in the same place. Also the "_" is for spaces and the "Me" needs to be replaced with my table name???

Thank You for your help. I have been struggling with this for too long!


Private Sub Sales_Order_AfterUpdate()
Tx_Test_Data![Sales_Order].Tag = Tx_Test_Data![Sales_Order].Value
End Sub

Private Sub Sales_Order_Enter()
If Not Tx_Test_Data.NewRecord Then Exit Sub
If Not (IsNull(Tx_Test_Data![Sales_Order].Tag) Or Tx_Test_Data![Sales_Order].Tag = " ") Then
Tx_Test_Data![Sales_Order].Value = Tx_Test_Data![Sales_Order].Tag
End If
End Sub
 
here's how it would work on your form:

In the After Update event of the Sales_Order field put code like this:
Me![Sales_Order].Tag = Me![Sales_Order].Value

In the On Enter Event of the same field put code like this:
If Not Me.NewRecord Then Exit Sub
If Not (IsNull(Me![Sales_Order].Tag) Or Me![Sales_Order].Tag = "") Then
Me![Sales_Order].Value = Me![Sales_Order].Tag
End If

- Note!: this won't work when the form is first opened - it only works after the user has entered something (after update) and then goes to a new record.
- missinglinq's post might work better for you (?) but the user must use the command button. you might want to hide the navigation buttons forcing the user to use the button.
 
Missinglinq and Wazz

Thank you both for your help. Sorry it took so long. Other things came up that needed attention and I just got back to this the other day. I am using a duplicate button and that works good, except the duplicate message when you exit. Thanks again.

jdr1994 :)
 
If you're getting a message about a "duplicate" one of the values you're copying forward has, in its Table definition, Indexed set to Yes (No duplicates). Assuming Duplicates are OK (since you've intentionally copied it forward) you need to change that to Yes (Duplicates OK). Or, if you don't want it duplicated, don't use the code to bring it forward.
 
This is ok.. I set "Yes(No Duplicate)" in table, but how i can suppress MSOffice Error Message and show mine, own, different. ( Need i do anything in my form)
 

Users who are viewing this thread

Back
Top Bottom