JustAnswer > Programming
Ask A Question|Register|Login|Help
JustAnswer

Programming

Ask a Programming Question, Get an Answer ASAP!

Have your own Programming question?

8 Programmers are Online Now
characters left:
Not a Programming Question?
Bookmark and Share

Question

I am trying to program a button in Microsoft Access. That when it is clicked it will duplicate the existing record and change the serial number (primary key) by adding 1(e.g. 58432 to 58433) on the creation of the new record. Can you help?

Submitted: 123 days and 4 hours ago.
Category: Programming
Value: $17
Status: AWAITING EXPERT REPLY
+
Read More

Optional Information

Computer OS: Windows XP
Browser: IE

Posted by dawber39 123 days and 1 hours ago.

Info Request

Hi and thank you for choosing JUst Answer

Do you assign the primary key - or does Access Assign it?

122 days and 10 hours ago.

Reply

I can choose the primary key in Access.

 

 

Posted by dawber39 122 days ago.

Info Request

I know - you can choose the primary key in Access - My question was

Do you assign the primary key - or does Access Assign it?

Is it something you enter - or is it Auto Number?

121 days and 8 hours ago.

Reply

Hello,

 

Right now it is something we pull from an existing table/query, but, can be entered if needed.

 

James

 

Posted by dawber39 121 days and 4 hours ago.

Info Request

I do not think you are understanding my question

In the table that holds the records that this primary key is assigned to - Is it auto numbered or do you have to enter it?

121 days and 3 hours ago.

Reply

Sorry for the confusion. We do have to enter it manually.

 

James

 

 

Posted by dawber39 121 days and 1 hours ago.

Info Request

Okay - Now, I assume you are putting this button that duplicates the record on a form that views these records?

Edited by dawber39 on 7/25/2009 at 12:22 AM

120 days and 20 hours ago.

Reply

That is correct.

 

James

 

 

Posted by dawber39 120 days and 8 hours ago.

Info Request

Okay James - I just need one more thing from you - I have some code for you - but I need to know if the serial number you are using as the primary key is a text field or a number field?

Thanks

Answer

I am assuming that your field is a numeric field This will duplicate all fields and add a 1 onto the primary key -

Attach this code to the click property of your button - dont forget to change the field names to your field names and if there are more fields just add another line where appropriate

Dim RstDup As DAO.Recordset

Set RstDup = Me.RecordsetClone

RstDup.FindFirst "PrimaryKeyField=" & Me!
PrimaryKeyField
If rstDup.NoMatch=False Then
Me.Recordset.AddNew
Me!
PrimaryKeyField= RstDup!PrimaryKeyField * 10 +1
Me!NameField1 = RstDup!NameField1
Me!NameField2 = RstDup!NameField2
Me!NameField3 = RstDup!NameField3
Me!NameField4 = RstDup!NameField4
End If
RstDup.Close
Set RstDup = Nothing

Picture
Expert: dawber39
Pos. Feedback: 100.0 %
Accepts: 
Answered: 7/25/2009

Database Administrator

Associates in Computer Information Systems, Database Analyst, SQL, Access

108 days and 9 hours ago.

Reply

Hello sorry it has taken so long to get back to you. I was on vacation. I attached the code to the click property and changed the field names but am getting a compile error. Hopefully you can read this the printing is pretty small. Not sure what we're missing. Thank you for your patience with us.
graphic
View Full Image
.



+
Read More

Related Programming Questions

  • Javascript Html question. I have a script in a Html documant
  • I have used excel 2003 web query to retrieve data from a sec...
  • I don't have so much a question as a need for programming se...
  • I need help with a dreamweaver problem on my website http://...
  • I need to write a formula to annualize 552973.00 with a begi...
  • Do by Visual Basic 2008 Express Edition Attach three (3)
  • to be Done by Visual Basic 2008 Express Edition submit
  • Analysing text files to obtain statistics on their content



Disclaimer: Information in questions, answers, and other posts on this site ("Posts") comes from individual users, not JustAnswer; JustAnswer is not responsible for Posts. Posts are for general information, are not intended to substitute for informed professional advice (medical, legal, veterinary, financial, etc.), or to establish a professional-client relationship. The site and services are provided "as is" with no warranty or representations by JustAnswer regarding the qualifications of Experts. To see what credentials have been verified by a third-party service, please click on the "Verified" symbol in some Experts' profiles. JustAnswer is not intended or designed for EMERGENCY questions which should be directed immediately by telephone or in-person to qualified professionals.
Question List | Become an Expert | Terms of Service | Security & Privacy | About Us
© 2003-2009 JustAnswer Corp.