Solved

Move specific record to another table Access 2003

Posted on 2008-06-24
6
602 Views
Last Modified: 2008-07-03
I like to move a complete specific selected record in a form to table for archiving.

original table is called tbl_hw and archiving table is called tbl_hw_archive.
Both tbl_hw and tbl_hw_archive have the same filds.

How can I select on record and add this record including all filds to the other table and after this is done delete this record in the original table.

Best regards.
0
Comment
Question by:jesaja
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 44

Accepted Solution

by:
Arthur_Wood earned 250 total points
ID: 21856321
the SQL would look like this:

INSERT INTO tbl_hw_archive Select * from tbl_hw where tbl_hw.<PrimaryKeyField> = SomeValue


Not knowing what the fields are in your tables, you would replace .<PrimaryKeyField> with the name of the field in the table that is the PrimaryKey of that table, and replace SomeValue with the Primary_Key_Value of the record that you wish to copy to the archive table.

AW
0
 
LVL 44

Assisted Solution

by:GRayL
GRayL earned 250 total points
ID: 21857549
You cannot INSERT and DELETE from the same SQL.  Once you are satisfied that the record has indeed been inserted in the archive table, run a DELETE query on the original:

DELETE * from tbl_hw WHERE tbl_hw.pk = SomeValue
0
 
LVL 44

Expert Comment

by:GRayL
ID: 21857562
Reading it again, do you expect to perform this action by opening the table directly, or are you doing it from a form?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Author Comment

by:jesaja
ID: 21860297
Both thanks for your advice forgot about using SQL in a form.

I did this:


Me.Painting = False
    DoCmd.Hourglass True
    DoCmd.SetWarnings False
    
    If (MsgBox("Wollen Sie den aktuellen Datensatz: " & Chr(34) _
            & Me![Temp_ID_Hardware] & " - " & Me![Temp_Model_Name] & Chr(34) & _
        " archivieren?", vbExclamation + vbYesNo + vbDefaultButton2) = 6) Then
       
        DoCmd.RunSQL "INSERT INTO tbl_hw_archive Select * from tbl_hw where tbl_hw.ID_Hardware = " & Me![Temp_ID_Hardware] & ""
        
        If (MsgBox("ACHTUNG!" & Chr(10) & "Wollen Sie den aktuellen Datensatz: " & Chr(34) _
            & Me![Temp_ID_Hardware] & " - " & Me![Temp_Model_Name] & Chr(34) & _
        " löschen?", vbCritical + vbYesNo + vbDefaultButton2) = 6) Then
            
         DoCmd.RunSQL "DELETE * from tbl_hw WHERE tbl_hw.ID_Hardware = " & Me![Temp_ID_Hardware] & ""
        
        End If
    
    End If
               
    DoCmd.Hourglass False
    Me.Painting = True
    DoCmd.SetWarnings True
    
    If Err = 0 Then
        MsgBox ("Der Datensatz wurde ordnungsgemäss archiviert und von der Haupttabelle gelöscht!"), vbInformation, AppName
        Me.Refresh
    End If

Open in new window

0
 
LVL 44

Expert Comment

by:GRayL
ID: 21860376
Thanks, glad to help.
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 21862467
Glad to be of assistance

AW
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question