Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Access 2010: Create revision records for subform data

Posted on 2014-04-10
8
Medium Priority
?
487 Views
Last Modified: 2014-04-11
We have an Access Database form with a Main form and 7 subforms.

We would like to allow the user to create a revision to the main document and the subforms while maintaining the the original version of the data.

The subforms are linked to the mainform using the DocumentID

We already have created code using the DAO method to create the revision in the main form

Now we need to query the data in the subforms and write the data to the subform tables with the new DocumentID number.

I was thinking of using the Insert Into  and a select statement like this:

    Set dbData = CurrentDb()
    strTS = "INSERT INTO tblDocumentProceduresTS(DocumentID, ProcedureID, ProcedureName)" & _
            "SELECT me.NewRevision as tblDocumentProcedureTS.DocumentID, tblDocumentProceduresTS.ProcedureID, tblDocumentProceduresTS.ProcedureName " & _
            "FROM tblDocumentProceduresTS " & _
            "WHERE (((tblDocumentProceduresTS.DocumentID)=" & Me.DocumentID & "));"
   
    MsgBox (strTS)
    Set rs = dbData.OpenRecordset(strTS)
    doData.Execute strTS
0
Comment
Question by:btgtech
[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
  • 4
  • 4
8 Comments
 
LVL 38

Expert Comment

by:Jim P.
ID: 39993295
The code looks good. So what is the question?
0
 

Author Comment

by:btgtech
ID: 39994552
I do not have any new records showing up in the tblDocumentProceduresTS.

Can I use the same field as the criteria for the select statement and set it to a new value in the same select statement?
0
 

Author Comment

by:btgtech
ID: 39994562
I noticed that the execute command above used DoData instead of dbdata.  I made this change but now I get an error:

Number of query values and destination fields are not the same.
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 38

Expert Comment

by:Jim P.
ID: 39994692
Try chaning the code to this:

    strTS = "INSERT INTO tblDocumentProceduresTS(DocumentID, ProcedureID, ProcedureName) " & _
            "SELECT me.NewRevision as tblDocumentProcedureTS.DocumentID, tblDocumentProceduresTS.ProcedureID, tblDocumentProceduresTS.ProcedureName " & _
            "FROM tblDocumentProceduresTS " & _
            "WHERE (((tblDocumentProceduresTS.DocumentID)=" & Me.DocumentID & "));"
   
    MsgBox (strTS)

    DoCmd.SetWarnings False
    DoCmd.RunSQL strTS 
    DoCmd.SetWarnings True

Open in new window

0
 

Author Comment

by:btgtech
ID: 39994705
This still has the same issue show up.

I do not have any new records showing up in the tblDocumentProceduresTS.

Can I use the same field as the criteria for the select statement and set it to a new value in the same select statement?
0
 
LVL 38

Accepted Solution

by:
Jim P. earned 2000 total points
ID: 39995285
You mean like this?

    strTS = "INSERT INTO tblDocumentProceduresTS(DocumentID, ProcedureID, ProcedureName) " & _
            "SELECT " &  Me.DocumentID & "  as DocumentID, ProcedureID,  ProcedureName " & _
            "FROM tblDocumentProceduresTS " & _
            "WHERE DocumentID = " & Me.DocumentID & ";"
   
    MsgBox (strTS)

    DoCmd.SetWarnings False
    DoCmd.RunSQL strTS 
    DoCmd.SetWarnings True

Open in new window

0
 

Author Comment

by:btgtech
ID: 39995382
No, If you look back at the code I posted, I want to select all of the records that are equal to the current DocumentID and set it equal to the NewRevision

So for example,

If Document ID = 1 and NewRevision = 301
then
1. Select all of the records with a DocumentID of 1
2. Insert the set of records into the same table with a DocumentID = NewRevision which is 301

Make sense?
0
 
LVL 38

Expert Comment

by:Jim P.
ID: 39995420
Change the  " &  Me.DocumentID & " to the " &  Me.NewRevision & ".
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

636 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