473,394 Members | 1,828 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,394 software developers and data experts.

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 2963
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("tIncomeAlloc", "Counter") _
& " FROM tIncomeAlloc " _
& "WHERE RecNo = " & vReceiptNumber, dbFailOnError

Public Function FieldNames(tblName 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(tblName)

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*****@earthlink.net> wrote in message
news:vQ*****************@newsread3.news.atl.earthl ink.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.com.au> wrote in message
news:40***********************@news.optusnet.com.a u...
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("tIncomeAlloc", "Counter") _
& " FROM tIncomeAlloc " _
& "WHERE RecNo = " & vReceiptNumber, dbFailOnError

Public Function FieldNames(tblName 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(tblName)

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*****@earthlink.net> wrote in message
news:vQ*****************@newsread3.news.atl.earthl ink.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("TableName", "PrimaryKeyField") _
& " FROM TableName " _
& "WHERE PrimaryKeyField = " & vPrimaryKeyField,
dbFailOnError

vPrimaryKeyField identifies the record you wish to copy.

--
Bob Darlington
Brisbane
"Marleen" <mm*****@earthlink.net> wrote in message
news:AX*****************@newsread3.news.atl.earthl ink.net...
Bob,

Thank you for your response!

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

Thanks!

Marleen
"Bob Darlington" <bo*@dpcmanAX.com.au> wrote in message
news:40***********************@news.optusnet.com.a u...
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("tIncomeAlloc", "Counter") _
& " FROM tIncomeAlloc " _
& "WHERE RecNo = " & vReceiptNumber, dbFailOnError

Public Function FieldNames(tblName 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(tblName)

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*****@earthlink.net> wrote in message
news:vQ*****************@newsread3.news.atl.earthl ink.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*****@earthlink.net> wrote in
news:vQ*****************@newsread3.news.atl.earthl ink.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 acCmdSelectRecord
.RunCommand acCmdCopy
.RunCommand acCmdPasteAppend
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
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...
1
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....
3
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....
19
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
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...
2
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...
0
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...
2
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...
7
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...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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.