UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Duplicate Record Button, Access 2010    
 
   
kolos
post Feb 20 2020, 02:42 PM
Post#1



Posts: 25
Joined: 18-December 07



Hello everyone,

I use the Duplicate record button on one form. And it works fine when I double the input.
However, sometimes I need to enter the same record 3, 4, 5 ... n times.
Is it possible to enter a certain number of the same entries based on the value of the text field.
For example, the number 4 is entered in the text field. The click button makes four identical entries in the table.
It doesn't work for me, no matter what I've tried pullhair.gif
Go to the top of the page
 
theDBguy
post Feb 20 2020, 03:06 PM
Post#2


UA Moderator
Posts: 77,715
Joined: 19-June 07
From: SunnySandyEggo


Hi. First question is, why are you duplicating records? Second question is, what exactly have you tried? Have you tried using a loop to call the button event x number of times?

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
kolos
post Feb 20 2020, 03:30 PM
Post#3



Posts: 25
Joined: 18-December 07



Multiple orders can be generated based on the number of requests. So under one request number, there may be more work orders that are assigned a custom ID number.
So all data is the same except the last data in the table that is generated for each row entered in the table.
The problem arises if i need to insert 3 or more orders.

Attached File(s)
Attached File  1.jpg ( 58.45K )Number of downloads: 4
Attached File  2.jpg ( 53.93K )Number of downloads: 4
 
Go to the top of the page
 
ADezii
post Feb 20 2020, 03:46 PM
Post#4



Posts: 2,815
Joined: 4-February 07
From: USA, Florida, Delray Beach


You may run into a little problem if the Duplicate Record Button contains an [Embedded Macro] as opposed to an [Event Procedure]. One approach that should work for sure is to directly write to the underlying Recordset X number of times. The following Code will do just that assuming the Value in [txtNumOfDups] is valid and is < 6. Obviously, make your own adjustments.
CODE
Dim intCtr As Integer

'Make sure that the Value in [txtNumOfDups] is Not NULL, is Numeric and is <=6
If IsNull(Me![txtNumOfDups]) Or Not IsNumeric(Me![txtNumOfDups]) Or Me![txtNumOfDups] > 6 Then Exit Sub

With Me.RecordsetClone
  For intCtr = 1 To Me![txtNumOfDups]
    .AddNew
      ![Last Name] = Me![txtLast]
      ![First Name] = Me![txtFirst]
      ![Job Title] = Me![txtTitle]
    .Update
  Next
End With

Me.Requery
Go to the top of the page
 
GroverParkGeorge
post Feb 20 2020, 03:48 PM
Post#5


UA Admin
Posts: 36,966
Joined: 20-June 02
From: Newcastle, WA


Unfortunately, this sounds very much like an inappropriate approach to the tables.


If all of the data points in those duplicated records are IDENTICAL except for the unique identifier, then those redundant data points don't belong in that table. There should be a one side table of requests for those data points that pertain to the request. Then, this many side table would have only two fields, the foreign key for the parent record and the unique identifier, or Work Order IDs.

That said, you can insert the appropriate foreign key value from the requests into the Work Order table with an insert query. And you can run that insert query as many times as needed.

CODE
For i = 1 to Forms!frmYourWorkOrderRequestForm.txtWorkOrderQuantity
     Currentdb.Execute "INSERT INTO WorkOrders (RequestID, WorkOrderID) " & _
           " VALUES (" & Forms!frmYourWorkOrderRequestForm.txtRequestID ", " &  CustomWorkOrderID, dbFailOnError

Next i


You'll need to replace my "CustomWorkOrderID" with a function call to generate the new, unique, custom work order IDs needed for each Work Order.

--------------------
My Real Name Is George. Grover Park Consulting is where I did business for 20 years.
How to Ask a Good Question
Beginning SQL Server
Go to the top of the page
 
kolos
post Feb 20 2020, 04:29 PM
Post#6



Posts: 25
Joined: 18-December 07



You're right. The problem is because i try to reorganize the base which was done "from the roof".
In the absence of time, I can't start it from the beginning.
I just have to work with what I got….
I have a bunch of tables without relationships, queries with many calculated fields etc, etc...
Anyway, you helped me a lot. Thank you for your help thanks.gif
Go to the top of the page
 
GroverParkGeorge
post Feb 20 2020, 05:29 PM
Post#7


UA Admin
Posts: 36,966
Joined: 20-June 02
From: Newcastle, WA


I understand the problem of no time to do the job over right. Unfortunately, it happens to everyone at some point.

Continued success with the project.

--------------------
My Real Name Is George. Grover Park Consulting is where I did business for 20 years.
How to Ask a Good Question
Beginning SQL Server
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    31st March 2020 - 08:08 AM