473,698 Members | 2,631 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Duplicate Record with Associated records

6 New Member
MS Acc 2003, XP

Thank you in advance for any help.

I have tables called "Makeup" and "Lines". Each makeup can have multiple lines.

Goal is to create a new "makeup" with identical "lines" except with a new makeup id.

I created a form Makeup Copy with Line Subform. In the main form there is ID (key field), Comments, Customer, Description plus an unbound field "NewMakeup" . Each line of the subform has the fields "Makeup (primary key), Line (primary key), Product, mm"

I added a duplicate button with code below, having the intention of duplicating the Makeup record with the NewMakeup replacing ID.

Append query has

Field: Makeup
Append to: Forms!Makeup Copy.Tag

then the line, product, and mm columns as usual

with the final column having
Field: NewMakeup: CLng(Forms![Makeup Copy]!Makeup)
Append to: Line

And here is the VB for the "duplicate" button:

Expand|Select|Wrap|Line Numbers
  1. Private Sub btnDuplicate_Click()
  2.  
  3. Dim dbs As DAO.Database
  4. Dim rst As DAO.Recordset
  5. Dim F As Form
  6.  
  7. 'return database variable pointing to current database
  8.  
  9. Set dbs = CurrentDb
  10. Set rst = Me.RecordsetClone
  11.  
  12. 'tag property to be used later by the append query
  13.  
  14. Me.Tag = Me![NewMakeup]
  15.  
  16. 'add new record to end of Recordset object
  17.  
  18. With rst
  19.     .AddNew
  20.     !ID = Me!NewMakeup
  21.     !Comments = Me!Comments
  22.     !Customer = Me!Customer
  23.     !Description = Me!Description
  24.     .Update                     'save changes
  25.     .Move 0, .LastModified
  26. End With
  27. Me.Bookmark = rst.Bookmark
  28.  
  29. 'duplicate all the associated lines
  30.  
  31. DoCmd.SetWarnings False
  32. DoCmd.OpenQuery "cpyMakeup"
  33. DoCmd.SetWarnings True
  34.  
  35. 'requery the subform to display the newly appended records
  36.  
  37. Me![Lines Subform].Requery
  38.  
  39. End Sub
  40.  

Results of clicking button:

Duplicate Output Destination 'Line'.

debugger then highlights this line:

DoCmd.OpenQuery "cpyMakeup"
Jun 17 '08 #1
1 2229
VinArt
6 New Member
I'm pretty sure the problem is with the query. I've made several attempted debugger always flags the line in the VB code for the button that points to the query.

Current status:

Field: Makeup
Append to: Forms!Makeup Copy!Tag

(I changed the Tag to equal the old ID rather than the new one)

and

Field: New: Cling(forms![Makeup Copy]!ID)
Append to: NewMakeup

Data type mismatch in criteria expression.
Jun 18 '08 #2

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

Similar topics

3
3221
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 it will run a search spotting out duplicate ID#'s. Than with in those ID#'s spot out duplicate dates. I could do this by eye and spend hours spotting out the duplicated dates, but it would be much easier and funner having a script do it for you.
1
4341
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 2nd record occurrence i.e. first duplicate record), update the field to 3 for the 3rd record occurrence i.e. 2nd duplicate record Example for a duplicated record (field with value ABCD) Rec 1 ABCD 1 Rec 2 ABCD ...
2
2775
by: Jason | last post by:
I have a table of 650,000 records associated to contracts. Some of the contracts have multiple records but each contract only has one Active Record (there might be several inactive records). There are dates associated with each of the records (whether active or inactive). I need to compare the dates between the active and inactive contract records. So far, I've created a "find duplicates query" for contract to identify contracts that...
8
3299
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 data in many of the fields so I paste in the same values of the previous record and then edit what needs edited in the new record saving much retyping of the same data. Doing this however creates the definite possibility of creating a duplicate...
3
28841
by: Nhmiller | last post by:
I searched here for an answer. I am entering records into a database, and it would save a lot of time if I could duplicate a record that is very similar to the new one I am about to enter, then make one or two changes to the new one. This is the problem I have with Access. Look at this answer! >Private Sub btnCopy_Click() >On Error GoTo handle_error > Set cnxn = CurrentProject.Connection > Set rs = New ADODB.Recordset
2
3231
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 primary key. My first attempt seemed to work(minus a few Microsoft glitches). I used a "duplicate" command button at first. This made a copy of the record but failed to bump up the primary key by 1 number(so it seemed). Actually, the number did...
0
2516
by: claus | last post by:
Hi, I am not a programmer but tries anyway to program a feature in a form where I am able to copy entries for the form and a subform. I have tried follow the guide here http://allenbrowne.com/ser-57.html, but my problem is that I have more than one keyfield in the join between the two tables: Hovedoplysninger and Itemoplysninger. The tree fields are: "Medarbejder", "Sagsnummer" and "Mandag". I have succeded creating the new entry...
4
4196
by: Thomas Arthur Seidel | last post by:
Hello to all, I have a small or big problem with a customer data base, where during a change of system we might have created duplicate records. This should be easy to find, you might think, but, we are talking about roughly 10000 records or less in a total volume of 1 MIO records or more. I have considered a strategy: The station ID and a field with something like a sequence number are supposed to be unique during that period. The...
1
7268
by: xraive | last post by:
I have a problem with this. Currently I am trying Allen's code and i am not successful. Current Design Table1 (Main Form) TravelID (PK) ApprovedBY EntreredBy BudgetCode ExpenseCode
0
8683
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8611
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9170
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9031
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8904
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8876
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4624
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2341
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.