New Record Button on a Form

richardcasci

Registered User.
Local time
Today, 12:09
Joined
Mar 23, 2012
Messages
16
Hello.

Working in Access 2010.

I currently have a button in my Form that automatically goes to a blank record and allows you to create a new record.

I would also like a button that creates a new record but duplicates the previous record.

My database tracks what products my employees work on every day and sometimes the only thing that may change is the date or the product #. So only a couple of the records may need to change.

However, other times I need to start from scratch and use my combo boxes to add a new record. Can you have both buttons? One that goes to a blank record and one that goes to a duplicate record???

thanks in advance.
 
Thank you.

However, it seems that these options would change the entire form to become default. Can I have both options? Also, that shows how to do it for Access 2007.
 
The cited code of Allen's will work in all versions of Access; he just referred to versions 2007 and later, because the code cannot be used with the new Multi-value Fields found in those versions. But not wanting to set the Default Values in this situation is understandable. The code will work for copying the Current Record as a New Record:
Code:
Private Sub DupRecord_Click()
 
 If Me.Dirty then Me.Dirty = False

 DoCmd.RunCommand acCmdSelectRecord
 DoCmd.RunCommand acCmdCopy
 DoCmd.GoToRecord , , acNewRec
 DoCmd.RunCommand acCmdPaste
    
End Sub

If you wanted to have one Field that was Null (empty) when copying like this, and you should have at least one field that is different, you could add a line like this:
Code:
Private Sub DupRecord_Click()
 
 If Me.Dirty then Me.Dirty = False

 DoCmd.RunCommand acCmdSelectRecord
 DoCmd.RunCommand acCmdCopy
 DoCmd.GoToRecord , , acNewRec
 DoCmd.RunCommand acCmdPaste
 
 Me.FieldToLeaveEmpty = Null    

End Sub

Linq ;0)>
 
The cited code of Allen's will work in all versions of Access; he just referred to versions 2007 and later, because the code cannot be used with the new Multi-value Fields found in those versions. But not wanting to set the Default Values in this situation is understandable. The code will work for copying the Current Record as a New Record:
Code:
Private Sub DupRecord_Click()
Code:
[B]If Me.Dirty then Me.Dirty = False[/B]
 
[B]DoCmd.RunCommand acCmdSelectRecord[/B]
[B]DoCmd.RunCommand acCmdCopy[/B]
[B]DoCmd.GoToRecord , , acNewRec[/B]
[B]DoCmd.RunCommand acCmdPaste[/B]
 
[B]End Sub[/B]

If you wanted to have one Field that was Null (empty) when copying like this, and you should have at least one field that is different, you could add a line like this:
Code:
Private Sub DupRecord_Click()
Code:
[B]If Me.Dirty then Me.Dirty = False[/B]
 
[B]DoCmd.RunCommand acCmdSelectRecord[/B]
[B]DoCmd.RunCommand acCmdCopy[/B]
[B]DoCmd.GoToRecord , , acNewRec[/B]
[B]DoCmd.RunCommand acCmdPaste[/B]
 
[B]Me.FieldToLeaveEmpty = Null    [/B]
 
[B]End Sub[/B]

Linq ;0)>


Thanks so much... I am a noobie. How do I get to copy that code into design view for this button?
 
Thanks so much... I am a noobie. How do I get to copy that code into design view for this button?



I found out where to put the code, but it does not change the effect of the button. nothing happens when it is clicked.
 
Does any VBA code run? Code does not run in 2007/2010 unless your database resides in a folder that has been declared a “trusted” location.

To trust your folder, click:
  1. Office Button (top left)
  2. Access Options (bottom of dialog)
  3. Trust Center (left)
  4. Trust Center Settings (button)
  5. Trusted Locations (left)
  6. Add new location (button)
Here's a visual for it, courtesy of BTAB Development:

http://www.btabdevelopment.com/ts/default.aspx?PageId=13

If that doesn't do it, you might check to see if you have a Missing Reference to Windows Common Controls. I have seen a report of this causing this problem, when moving up from previous versions.

Linq ;0)>
 
Does any VBA code run? Code does not run in 2007/2010 unless your database resides in a folder that has been declared a “trusted” location.



To trust your folder, click:
  1. Office Button (top left)
  2. Access Options (bottom of dialog)
  3. Trust Center (left)
  4. Trust Center Settings (button)
  5. Trusted Locations (left)
  6. Add new location (button)
Here's a visual for it, courtesy of BTAB Development:

If that doesn't do it, you might check to see if you have a Missing Reference to Windows Common Controls. I have seen a report of this causing this problem, when moving up from previous versions.

Linq ;0)>


It appears that it is already trusted. I am believing that I will not be able to have this function work for me. Thanks though. lol
 
Copy and paste the exact code you're using behind the command button.
 
Copy and paste the exact code you're using behind the command button.


Private Sub DupRecord_Click()
End Sub
If Me.Dirty Then Me.Dirty = False

DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdCopy
DoCmd.GoToRecord , , acNewRec
DoCmd.RunCommand acCmdPaste

End Sub
Private Sub Command223_Click()
End Sub
 
Well, it doesn't do anything when you click on the button because you've ended the Sub without entering any code into it!

Private Sub DupRecord_Click()
End Sub
If Me.Dirty Then Me.Dirty = False

DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdCopy
DoCmd.GoToRecord , , acNewRec
DoCmd.RunCommand acCmdPaste

End Sub
Remove the line that is in Red so that you have

Code:
Private Sub DupRecord_Click()

 If Me.Dirty Then Me.Dirty = False

   DoCmd.RunCommand acCmdSelectRecord
   DoCmd.RunCommand acCmdCopy
   DoCmd.GoToRecord , , acNewRec
   DoCmd.RunCommand acCmdPaste

End Sub
Your Command Button also has to be named DupRecord.

Linq ;0)>
 
Well, it doesn't do anything when you click on the button because you've ended the Sub without entering any code into it!


Remove the line that is in Red so that you have

Code:
Private Sub DupRecord_Click()
Code:
[B]If Me.Dirty Then Me.Dirty = False[/B]
 
[B]  DoCmd.RunCommand acCmdSelectRecord[/B]
[B]  DoCmd.RunCommand acCmdCopy[/B]
[B]  DoCmd.GoToRecord , , acNewRec[/B]
[B]  DoCmd.RunCommand acCmdPaste[/B]
 
[B]End Sub[/B]
Your Command Button also has to be named DupRecord.

Linq ;0)>


THANKYOU!!!!!!!!!

I learned ACCESS by watching youtube videos. This has made my life soooo much easier. Thanks again. It works great.
 

Users who are viewing this thread

Back
Top Bottom