Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 29th, 2004, 05:07 AM
Authorized User
 
Join Date: Apr 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default how duplicate a recordset of 2 tables

Hi all,
This is the challenge.
I take as example the NorthWind database coming with Access.
I want to add a button on the Orden form that allow me to add a new order exactly the same as the current order (including orderdetails records).

Sometimes the customer order exactly the same that last time, so on this situation such funcionality will be great.

How on earth can I do this?
What code do I need behind this button?

Thanks a lot
Francisco


 
Old September 30th, 2004, 09:48 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 128
Thanks: 0
Thanked 1 Time in 1 Post
Default

Francisco,
Create a button on your form. This button will do a VBA code.
The code will collect all info or values from the current form and subform, then add a new order to the table/s related to the form and subform.
I hope this helps.
John

 
Old October 1st, 2004, 03:17 AM
Authorized User
 
Join Date: Apr 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

John,
I should get that far, however what VBA code should I have to make it happen?
Thanks
Fran

 
Old October 1st, 2004, 01:11 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 128
Thanks: 0
Thanked 1 Time in 1 Post
Default

Fran,
For example you updated an Invoice Number of your vendor you purchased supplies. This sample would be PO (Purchase Order) system.
You have three tables. One is PO. Two Voucher tables, one is VN and the other is VN_Details.
This will be on the field Invoice_No AfterUpdate:
=Invoice_No_AfterUpdate()

Your VBA code event function will be as follows:


-------------------------------------------------

Public Function Invoice_No_AfterUpdate()
On Error GoTo Invoice_No_AfterUpdate_Err

    Dim rstUpdRec As New ADODB.Recordset
    Dim sqlUpdRec As String

    Dim strID, strInvoice_No

    strInvoice_No = Screen.ActiveForm.Invoice_No.Value
    strID = Screen.ActiveForm.ID.Value

    If IsNull(strID) Then
        DoCmd.CancelEvent

    ElseIf IsNull(strInvoice_No) Then
        DoCmd.CancelEvent

    Else

        '--------------------------------'
        ' Update ID record on VN table '
        '--------------------------------'
        sqlUpdRec = "SELECT Invoice_No FROM VN "
        sqlUpdRec = sqlUpdRec & "WHERE ID = """ & strID & """"
        rstUpdRec.Open sqlUpdRec, CurrentProject.Connection, adOpenKeyset, adLockPessimistic

        If rstUpdRec.EOF Then
            rstUpdRec.Close
            Set rstUpdRec = Nothing
        Else
            Do Until rstUpdRec.EOF
                rstUpdRec("Invoice_No").Value = strInvoice_No
                rstUpdRec.Update
                rstUpdRec.MoveNext
            Loop
            rstUpdRec.Close
            Set rstUpdRec = Nothing
        End If

        '----------------------------------------'
        ' Update ID record on VN_Details table '
        '----------------------------------------'
        sqlUpdRec = "SELECT Invoice_No FROM VN_Details "
        sqlUpdRec = sqlUpdRec & "WHERE ID = """ & strID & """"
        rstUpdRec.Open sqlUpdRec, CurrentProject.Connection, adOpenKeyset, adLockPessimistic

        If rstUpdRec.EOF Then
            rstUpdRec.Close
            Set rstUpdRec = Nothing
        Else
            Do Until rstUpdRec.EOF
                rstUpdRec("Invoice_No").Value = strInvoice_No
                rstUpdRec.Update
                rstUpdRec.MoveNext
            Loop
            rstUpdRec.Close
            Set rstUpdRec = Nothing
        End If

        '--------------------------------'
        ' Update ID record on PO table '
        '--------------------------------'
        sqlUpdRec = "SELECT Invoice_No "
        sqlUpdRec = sqlUpdRec & "FROM PO "
        sqlUpdRec = sqlUpdRec & "WHERE ID = """ & strID & """"
        rstUpdRec.Open sqlUpdRec, CurrentProject.Connection, adOpenKeyset, adLockPessimistic

        If rstUpdRec.EOF Then
            rstUpdRec.Close
            Set rstUpdRec = Nothing
        Else
            rstUpdRec("Invoice_No").Value = strInvoice_No
            rstUpdRec.Update
            rstUpdRec.Close
            Set rstUpdRec = Nothing
        End If

    End If

Invoice_No_AfterUpdate_Exit:
    Exit Function

Invoice_No_AfterUpdate_Err:
    MsgBox Err.Description
    Resume Invoice_No_AfterUpdate_Exit

End Function

----------------------------------------------

Hope this helps.
John








Similar Threads
Thread Thread Starter Forum Replies Last Post
Loop through 17 tables in RecordSet object didimichael C# 1 July 18th, 2008 06:53 AM
Display Record Frm 2Diff Tables&Without Duplicate future Classic ASP Databases 3 November 12th, 2006 12:16 PM
Recordset from "Views" instead of "Tables" DellTah Dreamweaver (all versions) 0 April 13th, 2005 11:37 AM
Convert ADO recordset to DAO recordset andrew_taft Access 1 May 5th, 2004 02:31 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.