Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA 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 10th, 2004, 02:31 PM
Authorized User
 
Join Date: Aug 2004
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Default Deleted Printers Table

I want to create some code that will delete printers from my printers table and automatically move them to a deleted table. I want to have this code do everything automatically. I am going to create a form that will ask what printer I want to delete, and when I type the name of the printer, all of the information that goes along with that printer will move into a table called tblDeletedPrinters. We need to do this so that when we delete one of our printers, we can have the information in a table in case we need to run queries on the data. Can someone help me with this?

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

Public Function Deleted_Yes_AfterUpdate()
On Error GoTo Deleted_Yes_AfterUpdate_Err

    Dim rstUpdRec As New ADODB.Recordset
    Dim sqlUpdRec As String
    Dim intPrinterId As Integer

    Dim strPrinter_Name
    Dim strDeleted_Yes

    intPrinterId = Screen.ActiveForm.PrinterId.Value
    strPrinter_Name = Screen.ActiveForm.Printer_Name.Value
    strDeleted_Yes = Screen.ActiveForm.Deleted_Yes.Value

    If IsNull(intPrinterId) Then
        DoCmd.CancelEvent
    ElseIf IsNull(strDeleted_Yes) Then
        DoCmd.CancelEvent
    Else
        '---------------------------------------------------'
        ' Update PrinterID Record on tblDeletedPrinter table '
        '---------------------------------------------------'
        sqlUpdRec = "SELECT * FROM tblDeletedPrinter WHERE PrinterId = " & intPrinterId
        rstUpdRec.Open sqlUpdRec, CurrentProject.Connection, adOpenKeyset, adLockPessimistic

        If rstUpdRec.EOF Then
            rstUpdRec.AddNew
            rstUpdRec("Printer_Name").Value = strPrinter_Name

            ' Add here other fields to be inserted. Same as above.

            rstUpdRec.Update
            rstUpdRec.Close
            Set rstUpdRec = Nothing

        Else
            rstUpdRec.Close
            Set rstUpdRec = Nothing
        End If
    End If

Deleted_Yes_AfterUpdate_Exit:
    Exit Function

Deleted_Yes_AfterUpdate_Err:
    MsgBox Err.Description
    Resume Deleted_Yes_AfterUpdate_Exit

End Function

You want code. Try this code.
Note you need to add other fields to be inserted in the tblDeletedPrinters.

John







Similar Threads
Thread Thread Starter Forum Replies Last Post
List the Available printers ajit Java Basics 2 May 4th, 2007 07:54 AM
Add Printers ldoodle Classic ASP Basics 2 November 14th, 2006 09:20 AM
Printing and printers neilsands Java Basics 1 May 4th, 2006 08:57 AM
ODBC Linked Table shows #Deleted in all fields Darron Michael Access 4 December 16th, 2005 03:00 PM
Delete Printers Table Teqlump VB Databases Basics 1 September 10th, 2004 04:45 PM





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