473,486 Members | 2,407 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Is there VB code or a Macro for duplicating a record then changing one field's value

13 New Member
Hi.

I'm working on a database and I though I tinker with Macros and VB, I am not very versed in them. So ANY help would be HUGELY appreciated!!!
(I'm using Access 2003)

What I need to do is, from a form I've created, I need to add a button so the end user can duplicate the record they are viewing, then update either the original or the duplicate record's field ["Status"] from its current value of "Active" to "Inactive".

So, the end result are two identical records, one with a status of active, the other inactive.

Can anyone help me with the code or a Macro??

Thanks in advance for any help you can provide!!!! :)
Mar 5 '08 #1
5 1397
missinglinq
3,532 Recognized Expert Specialist
You'll need to copy those fields you want to carry forward to variables, go to a new record then plug the variables value back into the fields on the new record, then fill in the other fields:

Expand|Select|Wrap|Line Numbers
  1. Private Sub CopyPartialRecord2NewRecordButton_Click()
  2.  
  3. ‘Assign field values to be carried forward to variables
  4. MyFirstField = Me.FirstField
  5. MySecondField = Me.SecondField
  6. MyThirdField = Me.ThirdField
  7.  
  8. 'Go to a new record
  9. DoCmd.GoToRecord , , acNewRec
  10.  
  11. 'Plug in old values from variables to new record
  12. Me.FirstField = MyFirstField
  13. Me.SecondField  = MySecondField 
  14. Me.ThirdField = MyThirdField 
  15.  
  16. End Sub
Welcome to TheScripts!

Linq ;0)>
Mar 5 '08 #2
ladybug76
13 New Member
I'll give it a whirl!
I can't thank you enough!!
Mar 5 '08 #3
ladybug76
13 New Member
Ok. I don't know where I went wrong.

I'm getting the following error
Method or data member not found.
*(The error message launched my code and highlighted the"Me.FirstField" section of the code)*



Some info that may help to understand what I'm trying (unsuccessfully) to do
  • There are 49 fields in the table that need copied.
  • Only 10 show on the form.
  • Only 1 needs updated.
  • The QTSeq field is an auto numbering PK


Here is a sample of my code

Expand|Select|Wrap|Line Numbers
  1. Private Sub CopyRecord2New_Button_Click()
  2.  
  3. 'Assign field values to be carried forward to variables
  4.  
  5. QTSeq = Me.FirstField   
  6. Rebate_File_Number = Me.SecondField
  7. Pharma_Name = Me.ThirdField
  8. Comm_Med = Me.FourthField
  9. Rebate_Period = Me.FifthField
  10. Record_Type = Me.SixthField
  11. [...  i went on to define the other 42 fields in the table, but won't bore you with it all here......]
  12.  
  13.  
  14. 'Go to a new record
  15. DoCmd.GoToRecord , , acNewRec
  16.  
  17. 'Plug in old values from variables to new record
  18.  
  19. Me.FirstField = QTSeq
  20. Me.SecondField = Rebate_File_Number
  21. Me.ThirdField = Pharma_Name
  22. Me.FourthField = Comm_Med
  23. Me.FifthField = Rebate_Period
  24. Me.SixthField = Record_Type
  25. [.... same here, relisted the other 42 fields the same way....]
  26.  
  27. Set Record_Type = "I"
  28.  
  29. End Sub
Mar 5 '08 #4
ladybug76
13 New Member
Never mind.. I figured out what I did wrong...

Thank you SOOOOO much for your help!!!
Mar 5 '08 #5
missinglinq
3,532 Recognized Expert Specialist
Glad we could help!

Linq ;0)>
Mar 6 '08 #6

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

Similar topics

1
1959
by: LenS | last post by:
If this is the wrong place to post this, please advise better place. Otherwise, I have created the following python program and it works. Running on XP. I think I am now at that stage of learning...
6
2495
by: Robin S. | last post by:
**Eric and Salad - thank you both for the polite kick in the butt. I hope I've done a better job of explaining myself below. I am trying to produce a form to add products to a table (new...
0
466
by: Tim | last post by:
Access 97: I have a table with a hyperlink field that I display on a form. I can click on the form field and the hyperlink activates correctly. However, if I try to activate the hyperlink using VB...
8
3193
by: Steph | last post by:
Hi. I'm very new to MS Access and have been presented with an Access database of contacts by my employer. I am trying to redesign the main form of the database so that a button entitled...
2
2255
by: Keith Austin | last post by:
I need to produce a macro for a project that I have to do in my course in IT "Certificate III IT (Software Applications) Unit ICAITUO18C". The macro needs to validate previously imported data from...
2
1588
by: MLH | last post by:
I have a form based on a table. The table has a Yes/No field. Its an A97 table. The form has a button that updates the value in the control from No to Yes for the record currently being edited. ...
6
1404
by: doncee | last post by:
This is the set up: is a date field on a form. Its control source is the field "date_entered" in"Table1". If there is a date showing in the date_entered field (Text6) & the status in Combo box2...
12
1563
by: DanG | last post by:
We're running Visual Studio 2003 version 1.1.4322 SP1 to build a web application. Something strange started happening this morning on one of my co- workers' Development Environments. The...
12
5555
by: magmike | last post by:
Accidentally deleted a record. Anyway to get it back? If not, I know the ID number - which is an autonumber field. Because of the related data from other tables, would I be able to create a new...
0
6964
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
7126
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
7175
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
7330
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...
1
4865
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4559
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1378
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 ...
1
598
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
262
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.