473,396 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

place duplicate record in 2nd table

I'm using a command button to duplicate a record and I would like to place the duplicated record in a different table, is it possible if so, how i can achive that?

Thanks for your help!
Dec 13 '07 #1
24 1732
missinglinq
3,532 Expert 2GB
You could do this with an Append Query, but unless you intend to delete the record from the original table after copying it to the new table, you'd be in gross violation of normalization!

Welcome to TheScripts!

Linq ;0)>
Dec 13 '07 #2
NeoPa
32,556 Expert Mod 16PB
Consider what you need.
There are situations (backup etc) where normalisation issues don't count.
Is your situation one of them? Only you know at this point, but it's an important issue to consider nevertheless.
Dec 13 '07 #3
thanks for your reply...
Ok, i changed the command button to a check box (because i could only figure out how to do an append query with a check box). How do i delete the record from the first table after duplicating it? that is without running another append query...is it possible?
Dec 13 '07 #4
NeoPa
32,556 Expert Mod 16PB
The usual (and probably easiest) way is to create and run a DELETE query specifying the Primary Key of the record in the WHERE clause.
Dec 13 '07 #5
thanks for the reply...I did create a delete query also, but i would like to some how combine both quries or use a comand button to run both queries at the same time...i'm really new at all this and even access for idiot book isn't much help on this matter....

I also placed a command button on the form and would like to run Both queries once the button is clicked...and i have no idea how to do it...i'm furitlessly playing with the code...any help will be great.
Dec 13 '07 #6
NeoPa
32,556 Expert Mod 16PB
Have the code to create and run the APPEND query in the same routine as the code to create and run the DELETE query.
I can't go into much more detail at this time as I have so few details of your situation.
Dec 13 '07 #7
Although i'm not using it for archiving purposes, but what i'm trying to do is pretty much same as archiving. i have one table which gets information from two forms....there is a reason for having two different forms instead of just one.

1st form is filled and printed out at the beginning of a project to obtain storm water permit.

2nd form is filled out after some time (sometime project is 10 year long) and print out to terminate the permit.

I have also queries and reports to track when an annual payment is due (each project has different billing date) and send email to project managers reminding them about payment.

Once the process of terminating the permit is started, i would like to move that project information to another table. As of right now, i have two command buttons on my notice of termination (NOT) form, 1 to run append query and the other one to run the delete query. I would like to have just one command button which does both. To accomplish this, i believe i'm going to need a micro, right? I have only taken one programming class many many years ago and hence don't know how to write a micro. Any help with this will be greatly appreciated.
Please let me know if you need more information.
Dec 13 '07 #8
NeoPa
32,556 Expert Mod 16PB
I wouldn't recommend using macros at all.
Post in here the code behind the two individual buttons and we'll see if we can't design you a "One size fits all" button that does the whole job.

By the way, notice Linq's comment was related to making copies WITHOUT then deleting the original. There is no such situation here, so you can relax on that score :)
Dec 13 '07 #9
i'm not really sure what is going on...one minute everything is working ok, the next minute i get the following error:


Microsoft office Access can’t append all the records in the append query.
Microsoft Office Access set 0 field(s) to Null due to a type conversion failure, and it didn’t add 1 record(s) to the table due to key violations, 0 record(s) due to lock violations, and 0 records(s) due to validation rule violations.


Weird thing is that I get this message when I hit delete command, not append. Its copying the data just fine.

here is the code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub add_Click()
  2. On Error GoTo Err_add_Click
  3.  
  4.     Dim stDocName As String
  5.  
  6.     stDocName = "NOI form table Query"
  7.     DoCmd.OpenQuery stDocName, acNormal, acEdit
  8.  
  9. Exit_add_Click:
  10.     Exit Sub
  11.  
  12. Err_add_Click:
  13.     MsgBox Err.Description
  14.     Resume Exit_add_Click
  15.  
  16. End Sub
  17. Private Sub delete_Click()
  18. On Error GoTo Err_delete_Click
  19.  
  20.     Dim stDocName As String
  21.  
  22.     stDocName = "NOI form table Query"
  23.     DoCmd.OpenQuery stDocName, acNormal, acEdit
  24.  
  25. Exit_delete_Click:
  26.     Exit Sub
  27.  
  28. Err_delete_Click:
  29.     MsgBox Err.Description
  30.     Resume Exit_delete_Click
  31.  
  32. End Sub
thanks for all the help.
Dec 13 '07 #10
sorry, ignore the code in the last message...this code is working with two command buttons
Expand|Select|Wrap|Line Numbers
  1. Private Sub add_Click()
  2. On Error GoTo Err_add_Click
  3.  
  4.     Dim stDocName As String
  5.  
  6.     stDocName = "NOI"
  7.     DoCmd.OpenQuery stDocName, acNormal, acEdit
  8.  
  9. Exit_add_Click:
  10.     Exit Sub
  11.  
  12. Err_add_Click:
  13.     MsgBox Err.Description
  14.     Resume Exit_add_Click
  15.  
  16. End Sub
  17.  
  18.  
  19.  
  20. Private Sub Remove_Click()
  21. On Error GoTo Err_Remove_Click
  22.  
  23.     Dim stDocName As String
  24.  
  25.     stDocName = "delete"
  26.     DoCmd.OpenQuery stDocName, acNormal, acNormal
  27.  
  28. Exit_Remove_Click:
  29.     Exit Sub
  30.  
  31. Err_Remove_Click:
  32.     MsgBox Err.Description
  33.     Resume Exit_Remove_Click
  34.  
  35. End Sub
thanks!
Dec 14 '07 #11
i got it to work with one command button with the following code, but it doesn't work if i'm on the record which needs to be moved and deleted....i have to move to the next record and then perform the action.

for example, if i check box on record one to append and delete, and press the command it doesn't work, but if i move to the next record and then press the command button, it works just fine. Is there a way around that? Thanks for all the help!
Expand|Select|Wrap|Line Numbers
  1. Private Sub add_Click()
  2. On Error GoTo Err_add_Click
  3.  
  4.  
  5.  
  6.     DoCmd.OpenQuery "NOI", acNormal, acEdit
  7.     DoCmd.OpenQuery "delete", acNormal, acNormal
  8. Exit_add_Click:
  9.     Exit Sub
  10.  
  11. Err_add_Click:
  12.     MsgBox Err.Description
  13.     Resume Exit_add_Click
  14.  
  15. End Sub
Dec 14 '07 #12
NeoPa
32,556 Expert Mod 16PB
It looks like you've already found the problems with your first couple of posts ;)
I can't check the queries (NOI & delete) that you've created and used as you use them by name rather than by executing the SQL. This should not be a problem, from what you say they are both working correctly anyway.
I would guess your latest problem is that the current record is locked by the form.
I'm not sure how one would move from one record to another (programatically) in a form I'm afraid.

PS. I think your "delete" query line should probably be changed to :
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenQuery "delete", acNormal, acEdit
Dec 14 '07 #13
NeoPa
32,556 Expert Mod 16PB
I haven't got your setup to test but try this code to see if it gets around your problem.
Be careful and make sure it doesn't move the wrong record though. It's hard to know exactly what's what your end so this may not be correct, but give it a go.
Expand|Select|Wrap|Line Numbers
  1. Private Sub add_Click()
  2. On Error GoTo Err_add_Click
  3.  
  4.     Call DoCmd.RunCommand(acCmdRecordsGoToNext)
  5.     DoCmd.OpenQuery "NOI", acNormal, acEdit
  6.     DoCmd.OpenQuery "delete", acNormal, acEdit
  7.     Call DoCmd.RunCommand(acCmdRecordsGoToPrevious)
  8.  
  9. Exit_add_Click:
  10.     Exit Sub
  11.  
  12. Err_add_Click:
  13.     MsgBox Err.Description
  14.     Resume Exit_add_Click
  15. End Sub
Dec 14 '07 #14
Thanks a lot! it works beautifully!
Dec 17 '07 #15
NeoPa
32,556 Expert Mod 16PB
No problem. Glad I could help.
By the way, when running queries from the code it's often considered neater to hide any query warnings that indicate how many records are deleted / copied etc. If you want to include that then try :
Expand|Select|Wrap|Line Numbers
  1. Call DoCmd.SetWarnings(False)
  2. 'Query(ies) here
  3. Call DoCmd.SetWarnings(True)
Dec 17 '07 #16
so my code will look like this? if so, it didn't work.
Expand|Select|Wrap|Line Numbers
  1. Call DoCmd.SetWarnings(False)
  2. Private Sub add_Click()
  3. On Error GoTo Err_add_Click
  4.  
  5.     Call DoCmd.RunCommand(acCmdRecordsGoToNext)
  6.     DoCmd.OpenQuery "NOI", acNormal, acEdit
  7.     DoCmd.OpenQuery "delete", acNormal, acEdit
  8.     Call DoCmd.RunCommand(acCmdRecordsGoToPrevious)
  9.  
  10. Exit_add_Click:
  11.     Exit Sub
  12.  
  13. Err_add_Click:
  14.     MsgBox Err.Description
  15.     Resume Exit_add_Click
  16.  
  17. Call DoCmd.SetWarnings(True)
  18. End Sub
Dec 18 '07 #17
NeoPa
32,556 Expert Mod 16PB
Not exactly. The only code between the two new lines is the queries.
IE :
Expand|Select|Wrap|Line Numbers
  1. Private Sub add_Click()
  2. On Error GoTo Err_add_Click
  3.  
  4.     Call DoCmd.RunCommand(acCmdRecordsGoToNext)
  5.     Call DoCmd.SetWarnings(False)
  6.     DoCmd.OpenQuery "NOI", acNormal, acEdit
  7.     DoCmd.OpenQuery "delete", acNormal, acEdit
  8.     Call DoCmd.SetWarnings(True)
  9.     Call DoCmd.RunCommand(acCmdRecordsGoToPrevious)
  10.  
  11. Exit_add_Click:
  12.     Exit Sub
  13.  
  14. Err_add_Click:
  15.     MsgBox Err.Description
  16.     Resume Exit_add_Click
  17.  
  18. End Sub
Dec 18 '07 #18
Thanks! it works great. Is there a way to move automatically to next record after deletion...as of right now, it shows #delete in the fields?
Dec 26 '07 #19
NeoPa
32,556 Expert Mod 16PB
Try the following after the code that does the work :
Expand|Select|Wrap|Line Numbers
  1. Call Me.ReQuery()
Dec 28 '07 #20
nope. that didn't work :(
Jan 15 '08 #21
PianoMan64
374 Expert 256MB
just ry me.requery at the end off that sub routine
Jan 15 '08 #22
NeoPa
32,556 Expert Mod 16PB
nope. that didn't work :(
So what does it do? What did you notice?
Jan 15 '08 #23
So what does it do? What did you notice?
it works now :-) I was placing it at the wrong place - I was placing it after the code that hide the warring message instead of right after the code that runs the delete query.

thanks for the help.
Jan 16 '08 #24
NeoPa
32,556 Expert Mod 16PB
No worries Shaffy. I'm pleased you got it sorted :)
Jan 17 '08 #25

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Giloosh | last post by:
Hello, i need some help if possible... i have a payments table with over 500 records i want to run a query that searches through the table spotting out any duplicate ID#'s and Dates. So basically...
1
by: Robert | last post by:
How can I query an existing table and update a field in each record in the table with the occurrence count of each record e.g. update field to 1 (= first record occurrence), update field to 2 for...
8
by: Mark | last post by:
When my form goes to a new record, I have a procedure that copies the last record added to the form's underlying table into the form. The intent is that a series of new records may have the same...
2
by: stranger | last post by:
My database is set up so people can input parts orders. Sometimes they order the same parts on a monthly basis. I want to be able to duplicate past parts orders and have it pasted in with a new...
6
by: planetthoughtful | last post by:
Hi All, I have a C# ASP.NET page that submits back to itself to insert details from a form into a database table. When / if the user refreshes the page (and gets the standard warning that POST...
5
by: Manish | last post by:
The topic is related to MySQL database. Suppose a table "address" contains the following records ------------------------------------------------------- | name | address | phone |...
4
by: FangQ | last post by:
hi I am very new to mysql. I have a question about using the "on duplicate update" clause with insert command. my table "data" has two columns, field1 and field2, where field1 is the index...
8
by: Iona | last post by:
Hi Allan, I'm using a nifty piece of code you put on here some time back to do a duplicate entry check as below. I'm using to check for duplicate names. However I am getting an error message on...
1
by: SirTKC | last post by:
Hi, Here is the following scenario. I do have a master table with related subforms from wich I need to create a revision. But I need to duplicate the content of the subforms and link them to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.