Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / New Users / April 2005

Tip: Looking for answers? Try searching our database.

Help copying data

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Fuzzy Logic - 07 Apr 2005 22:52 GMT
I have two tables in the same database that have the identical fields. The
only difference is the second table has an additional date field for an
archival date. I need a way to move the data from one table to the other and
prompt for the archival date. Any suggestions on the best/easiest way to do
this?

TIA
John Vinson - 08 Apr 2005 00:26 GMT
>I have two tables in the same database that have the identical fields. The
>only difference is the second table has an additional date field for an
[quoted text clipped - 3 lines]
>
>TIA

Create an Append query based on the first table. In a vacant Field
cell type

[Archive date:]

to prompt for the date.

Do note that it's probably of zero benefit to have a table and an
archive table in the same database. There is no explicit limit on the
size of a table; the limit is on the entire size of the database, and
having the data in two tables instead of one will use MORE disk space,
not less. With proper indexing you shouldn't need to split the data
into two tables anyway. Could you consider just having a Yes/No field
[Archived]? Base your forms on queries selecting the appropriate value
of this field; on the form that lets you archive a record, you can set
the ArchivedDate field in the AfterUpdate event of the checkbox bound
to [Archived].

                 John W. Vinson[MVP]    
PC Datasheet - 08 Apr 2005 04:37 GMT
You probably don't even need the Yes/No field, [Archived]! If the
ArchivedDate field is Null, the record is not archived. If it is not Null,
the record is archived.

--
                                       PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
                             resource@pcdatasheet.com
                                www.pcdatasheet.com

> >I have two tables in the same database that have the identical fields. The
> >only difference is the second table has an additional date field for an
[quoted text clipped - 23 lines]
>
>                   John W. Vinson[MVP]
Fuzzy Logic - 08 Apr 2005 20:37 GMT
>>I have two tables in the same database that have the identical fields.
>>The only difference is the second table has an additional date field for
[quoted text clipped - 23 lines]
>
>                   John W. Vinson[MVP]    

OK I simplified things in hopes of understanding what the procedure is to
copy an entire record from one table to another with the same fields except
one. What I really wish to do is:

1) Prompt for a record to delete from the active table
2) move said record from the active table to the archive table (by move I
mean add to the archive table and delete from the active table).
3) add the archive date to said record (prompt for this as well)

I don't understand how and update query will do this. I don't see where the
data is being taken from the active table and moved to the archive table.
Please be as explicit as possible as I seem to be missing something obvious.
John Vinson - 14 Apr 2005 21:47 GMT
>> Do note that it's probably of zero benefit to have a table and an
>> archive table in the same database. There is no explicit limit on the
[quoted text clipped - 21 lines]
>data is being taken from the active table and moved to the archive table.
>Please be as explicit as possible as I seem to be missing something obvious.

Bob, please reread my message above.

I assert - pretty strongly! - that what you are asking to do (moving a
record from a main table to an archive table) SHOULD NOT BE DONE. It's
counterproductive; the yes/no field in the main table IS A BETTER
ALTERNATIVE.

That said... if you really, really want to do it that way anyhow, then
you are correct, an update query will not work.

Instead you will need to write VBA code to run an Append query
followed by a Delete query in succession. These should be wrapped in a
Transaction, to ensure that either both queries run successfully or
neither runs at all. The Append query could contain a calculated field
to append to the ArchiveDate field, defined as

ArchiveDate: Date()

I cannot write this query for you because I cannot see your table, I
do not know how you are selecting the record, and I do not know the
names of the fields in either table. But assuming you have the Append
and Delete queries written, referencing a control on the form to
select the desired record, the code for the button click event might
be:

Private Sub cmdArchive_Click()
Dim ws As Workspace ' need a workspace to do a Transaction
Dim db As DAO.Database
Dim qd As DAO.Querydef
Dim prm As Parameter
Dim inTrans As Boolean
Set ws = DBEngine(0) ' current workspace
On Error GoTo Proc_Error ' trap any query errors
ws.BeginTrans
  iTrans = True
  Set db = CurrentDb
  Set qd = db.QueryDefs("appArchive") ' your archive append query
  For Each prm In qd.Parameters ' evaluate parameters
     prm.Value = Eval(prm.Name)
  Next prm
  qd.Execute dbFailOnError
  Set qd = db.QueryDefs("delArchive")
  For Each prm In qd.Parameters ' evaluate parameters
     prm.Value = Eval(prm.Name)
  Next prm
  qd.Execute dbFailOnError
  ' if all is well, commit the transaction
ws.Commit
Proc_Exit:
  Exit Sub
Proc_Error:
  If InTrans Then
      ws.Rollback
      MsgBox "Unable to archive record", vbOKOnly
  End If
Resume Proc_Exit
End Sub

                 John W. Vinson[MVP]    
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.