473,769 Members | 2,355 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Copy Previou Record

I have a database that manages my webstore. Each store item record has 26
fields. I would like to have a way when adding new items to be able to just copy
the previous item when most everything is the same for the current item being
added. Could someone offer a suggestion on how to accomplish this.

Thank you very much!

Marleen
Nov 12 '05 #1
4 2984
Marleen,
There may well be a more elegant way, but I use the 'FieldNames' function
below to create a list of fields in the form's underlying query, where
'exclFld' is field to be ignored (normally Autonumber primary index field).
Then I use the resultant list as follows:

db.Execute "INSERT INTO tIncomeAllocAdd SELECT " _
& FieldNames("tIn comeAlloc", "Counter") _
& " FROM tIncomeAlloc " _
& "WHERE RecNo = " & vReceiptNumber, dbFailOnError

Public Function FieldNames(tblN ame As String, exclFld As String) As String
On Error GoTo ErrorFieldNames
Dim fldNames As String, td As TableDef, qd As QueryDef, db As Database, fld
As Field

Set db = CurrentDb
Set qd = db.QueryDefs(tb lName)

For Each fld In qd.Fields
If fld.Name <> exclFld Then
If fldNames <> "" Then
fldNames = fldNames & ", [" & fld.Name & "]"
Else
fldNames = "[" & fld.Name & "]"
End If
End If
Next

FieldNames = fldNames
Exit Function

ErrorFieldNames :
MsgBox Error$
Exit Function
End Function

Hope this helps.
--
Bob Darlington
Brisbane
"Marleen" <mm*****@earthl ink.net> wrote in message
news:vQ******** *********@newsr ead3.news.atl.e arthlink.net...
I have a database that manages my webstore. Each store item record has 26
fields. I would like to have a way when adding new items to be able to just copy the previous item when most everything is the same for the current item being added. Could someone offer a suggestion on how to accomplish this.

Thank you very much!

Marleen

Nov 12 '05 #2
Bob,

Thank you for your response!

Could you give me a thumbnail sketch of how this works.

Thanks!

Marleen
"Bob Darlington" <bo*@dpcmanAX.c om.au> wrote in message
news:40******** *************** @news.optusnet. com.au...
Marleen,
There may well be a more elegant way, but I use the 'FieldNames' function
below to create a list of fields in the form's underlying query, where
'exclFld' is field to be ignored (normally Autonumber primary index field).
Then I use the resultant list as follows:

db.Execute "INSERT INTO tIncomeAllocAdd SELECT " _
& FieldNames("tIn comeAlloc", "Counter") _
& " FROM tIncomeAlloc " _
& "WHERE RecNo = " & vReceiptNumber, dbFailOnError

Public Function FieldNames(tblN ame As String, exclFld As String) As String
On Error GoTo ErrorFieldNames
Dim fldNames As String, td As TableDef, qd As QueryDef, db As Database, fld
As Field

Set db = CurrentDb
Set qd = db.QueryDefs(tb lName)

For Each fld In qd.Fields
If fld.Name <> exclFld Then
If fldNames <> "" Then
fldNames = fldNames & ", [" & fld.Name & "]"
Else
fldNames = "[" & fld.Name & "]"
End If
End If
Next

FieldNames = fldNames
Exit Function

ErrorFieldNames :
MsgBox Error$
Exit Function
End Function

Hope this helps.
--
Bob Darlington
Brisbane
"Marleen" <mm*****@earthl ink.net> wrote in message
news:vQ******** *********@newsr ead3.news.atl.e arthlink.net...
I have a database that manages my webstore. Each store item record has 26
fields. I would like to have a way when adding new items to be able to

just copy
the previous item when most everything is the same for the current item

being
added. Could someone offer a suggestion on how to accomplish this.

Thank you very much!

Marleen


Nov 12 '05 #3
Marleen,
FieldNames() just generates a string of field names to insert into the SQL,
instead of typing them individually.
One field in the table will be a primary key field which cannot be
duplicated, therefore it is excluded from the string (exclFld). For this
solution to work, this key must be an autonumber, otherwise an error will
occur.
The following statement might be clearer than my origianl post:

db.Execute "INSERT INTO TableName SELECT " _
& FieldNames("Tab leName", "PrimaryKeyFiel d") _
& " FROM TableName " _
& "WHERE PrimaryKeyField = " & vPrimaryKeyFiel d,
dbFailOnError

vPrimaryKeyFiel d identifies the record you wish to copy.

--
Bob Darlington
Brisbane
"Marleen" <mm*****@earthl ink.net> wrote in message
news:AX******** *********@newsr ead3.news.atl.e arthlink.net...
Bob,

Thank you for your response!

Could you give me a thumbnail sketch of how this works.

Thanks!

Marleen
"Bob Darlington" <bo*@dpcmanAX.c om.au> wrote in message
news:40******** *************** @news.optusnet. com.au...
Marleen,
There may well be a more elegant way, but I use the 'FieldNames' function below to create a list of fields in the form's underlying query, where
'exclFld' is field to be ignored (normally Autonumber primary index field). Then I use the resultant list as follows:

db.Execute "INSERT INTO tIncomeAllocAdd SELECT " _
& FieldNames("tIn comeAlloc", "Counter") _
& " FROM tIncomeAlloc " _
& "WHERE RecNo = " & vReceiptNumber, dbFailOnError

Public Function FieldNames(tblN ame As String, exclFld As String) As String On Error GoTo ErrorFieldNames
Dim fldNames As String, td As TableDef, qd As QueryDef, db As Database, fld As Field

Set db = CurrentDb
Set qd = db.QueryDefs(tb lName)

For Each fld In qd.Fields
If fld.Name <> exclFld Then
If fldNames <> "" Then
fldNames = fldNames & ", [" & fld.Name & "]"
Else
fldNames = "[" & fld.Name & "]"
End If
End If
Next

FieldNames = fldNames
Exit Function

ErrorFieldNames :
MsgBox Error$
Exit Function
End Function

Hope this helps.
--
Bob Darlington
Brisbane
"Marleen" <mm*****@earthl ink.net> wrote in message
news:vQ******** *********@newsr ead3.news.atl.e arthlink.net...
I have a database that manages my webstore. Each store item record has 26 fields. I would like to have a way when adding new items to be able to

just copy
the previous item when most everything is the same for the current
item being
added. Could someone offer a suggestion on how to accomplish this.

Thank you very much!

Marleen



Nov 12 '05 #4
"Marleen" <mm*****@earthl ink.net> wrote in
news:vQ******** *********@newsr ead3.news.atl.e arthlink.net:
I have a database that manages my webstore. Each store item record has
26 fields. I would like to have a way when adding new items to be able
to just copy the previous item when most everything is the same for the
current item being added. Could someone offer a suggestion on how to
accomplish this.

Thank you very much!

Marleen


I run this code in the onClick event of a command button or the function
call of a pop up menu item, the caption of each being, "New Duplicate
Record".

With DoCmd
.RunCommand acCmdSelectReco rd
.RunCommand acCmdCopy
.RunCommand acCmdPasteAppen d
End With

--
Lyle
(for e-mail refer to http://ffdba.com/contacts.htm)
Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
383
by: Marleen | last post by:
I have a database that manages my webstore. Each store item record has 26 fields. I would like to have a way when adding new items to be able to just copy the previous item when most everything is the same for the current item being added. Could someone offer a suggestion on how to accomplish this. Thank you very much! Marleen
1
2567
by: Sean Howard | last post by:
Dear All, As is my want I need to do something in Access that seems simple but cannot fathom out. I have main form with two subforms, both datasheets with an almost identical table structure. I want to add the functionality to copy records from subformA to subformB WITHOUT USING COPY/PASTE. The reasonfor this is that I must
3
3217
by: david | last post by:
Hi, I've been reading tons of posts on how to copy records, but to no avail....i'm still stuck. There are three tables: Main, Sub-Form1 & Sub-Form2 I have a form which displays some data. The PK (ProductID) for each record on the form is an AUTONUMBER. This form also has a sub-form, linked via ProductID. The subform also
19
3478
by: davidgordon | last post by:
Hi, I need some pointers/help on how to do the following if it possible: In my access db, I have the following: Tables: Products, Sub-Assembly, Product-Pack Table, Products
5
1906
by: DraguVaso | last post by:
Hi, I need a SECURE way to copy parts of a file. I'm having files which contains a whole bunch of records. In one 'fysical' file I'm having one or more logical files. What I need to do is to copy a logical file (a part of the fysical file) into a new file. But the 'big' problem is: these records contains bankstatements, so I can't take the risk that there would be a record missing, or even one little charachter. The copy I make has to...
2
2871
by: josephm | last post by:
Hello Group: My first post on the group.Hope I get a response. I have a modest Fire Insurance ACCES Db.Thanks to this group - for the code. A "wanna be programmer"... "LEARNS" The code here-under (from the Archive) duplicates the EXPIRING records but affords the USER to give ONLY A NEW POLICY NO (NewKey),should a client opt to renew upon expiry of the YEARLY POLICY.The NEW POLICY NO is save as a NEW record along with the "old"static...
0
2152
by: igendreau | last post by:
I have a database with a Header table. Each record in tblHeader has two One-to-Many Relationships: with tblLines and tblKeys. The HeaderID field ties tblHeader to the other two tables. The data collected in tblHeader is simple: HeaderID (unique), a text description field, and a date field. I need to be able to copy header and it's related info. I have a form with a "Copy Source" combo box allowing the user to select a Header...
2
3469
by: Swinky | last post by:
I hope someone can help...I feel like I'm walking in the dark without a flashlight (I'm NOT a programmer but have been called to task to do some work in Access that is above my head). I have code that will successfully copy a record and append the information to a new record in the same table (parent table) within a form. However, there are related child tables with primary keys (set to Autonumber) stored in sub-forms. That information...
7
8696
kcdoell
by: kcdoell | last post by:
Good morning everyone: I created a form and set the default view as a continuous form. Basically the form is displaying records in which the user can add or edit new ones. The record source for this form is a query that I built that is based on a table. I have been working on this for several weeks and now I have been told that many times when a user wants to create a new record, much of the information that is displayed in a...
0
9589
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
9423
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
10050
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...
0
9866
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...
1
7413
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3967
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
3570
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.