Solved

Delete SQL 3219

Posted on 2004-04-28
3
620 Views
Last Modified: 2008-02-01
Set rsInvoice = db.OpenRecordset("DELETE Invoice.* FROM Invoice")

Its says runtime error 3219 on this row, the whole code:

Dim Cost As Integer
Dim Total As Integer
Dim iFrom As Integer
Dim iTo As Integer
Dim Found As Boolean
Dim bTransfer As Boolean
Dim db As DAO.DataBase
Dim rsArrivals As DAO.Recordset
Dim rsInvoice As DAO.Recordset
Dim rsTransfer As DAO.Recordset
Dim rsRates As DAO.Recordset
Dim rsMisc As DAO.Recordset
Dim rsHotel As DAO.Recordset
Dim rsLocation As DAO.Recordset
Dim rsInvoiceNumber As DAO.Recordset

' open Database Connection
Set db = CurrentDb()

' open recordset Arrivals
Set rsArrivals = db.OpenRecordset("SELECT *, Arrivals.[Party ID] AS ID FROM (Arrivals INNER JOIN Party ON Party.[Party ID] = Arrivals.[Party ID]) INNER JOIN [Tour Operator] ON Party.[Tour Operator] = [Tour Operator].[Tour Operator ID] WHERE Party.[Tour Operator] = " & Me![Tour Operator] & " AND Arrivals.[Arrival Date] BETWEEN #" & Me!Date1 & "# AND #" & Me!Date2 & "#")
If Not rsArrivals.EOF Then
Found = True
End If

' open recordset Invoice
Set rsInvoice = db.OpenRecordset("DELETE Invoice.* FROM Invoice")
Set rsInvoice = db.OpenRecordset("SELECT * FROM Invoice")

Do While Not rsArrivals.EOF

    ' add new record to Table
    rsInvoice.AddNew
    rsInvoice![Reference ID] = rsArrivals![Reference ID]
    rsInvoice![Party Name] = rsArrivals![Party Name]
   
    Set rsTransfer = db.OpenRecordset("SELECT * FROM Transfers WHERE [Party ID] = " & rsArrivals!ID)
    If Not rsTransfer.EOF Then
    bTransfer = True
    End If
   
    Do While Not rsTransfer.EOF
        Set rsHotel = db.OpenRecordset("SELECT Direction FROM Hotel WHERE Hotel = '" & rsTransfer![Transfer From] & "'")

        If rsHotel.EOF Then
            Set rsLocation = db.OpenRecordset("SELECT Direction FROM Locations WHERE Location = '" & rsTransfer![Transfer From] & "'")
            If Not rsLocation.EOF Then
                iFrom = rsLocation!Direction
            End If
            rsLocation.Close
            Set rsLocation = Nothing
        Else
            iFrom = rsHotel!Direction
        End If
        rsHotel.Close

        Set rsHotel = db.OpenRecordset("SELECT Direction FROM Hotel WHERE Hotel = '" & rsTransfer![Transfer To] & "'")
        If rsHotel.EOF Then
            Set rsLocation = db.OpenRecordset("SELECT Direction FROM Locations WHERE Location = '" & rsTransfer![Transfer To] & "'")
            If Not rsLocation.EOF Then
                iTo = rsLocation!Direction
            End If
            rsLocation.Close
            Set rsLocation = Nothing
        Else
            iTo = rsHotel!Direction
        End If
        rsHotel.Close
        Set rsHotel = Nothing
       
        Set rsRates = db.OpenRecordset("SELECT Cost FROM [Transfer Rates] WHERE [Tour Operator] = " & Me![Tour Operator] & " AND From = " & iFrom & " AND To = " & iTo & " AND [Transfer Type] = " & rsTransfer![Transfer Type])
        If Not rsRates.EOF Then
            Cost = Cost + rsRates!Cost
        End If
        rsTransfer.MoveNext
    Loop
    Total = Cost
    rsInvoice!Transfer = Cost
    Cost = (rsArrivals!Adults + (rsArrivals!Childs * rsArrivals![Child Handling])) * rsArrivals![Handling Fee]
    Total = Total + Cost
    rsInvoice!Handling = Cost
    Cost = rsArrivals![Agent Fee]
    Total = Total + Cost
    rsInvoice!Agent = Cost
   
    Set rsMisc = db.OpenRecordset("SELECT DISTINCTROW Miscellaneous.[Party ID], Sum(Miscellaneous.Cost) AS Total FROM Miscellaneous WHERE Miscellaneous.[Party ID] = " & rsArrivals!ID & " GROUP BY Miscellaneous.[Party ID]")
    If Not rsMisc.EOF Then
    Cost = rsMisc!Total
    Total = Total + Cost
    rsInvoice!Misc = Cost
    End If
   
    rsInvoice!Total = Total
    rsInvoice.Update
    rsArrivals.MoveNext
Loop

' close recordset
If bTransfer Then
rsRates.Close
Set rsRates = Nothing
End If
If Found Then
rsMisc.Close
Set rsMisc = Nothing
rsTransfer.Close
Set rsTransfer = Nothing
End If
rsInvoice.Close
Set rsInvoice = Nothing
rsArrivals.Close
Set rsArrivals = Nothing

Set rsInvoiceNumber = db.OpenRecordset("LastInvoiceNumber")
Cost = rsInvoiceNumber!LastInvoiceNumber
rsInvoiceNumber!LastInvoiceNumber = Cost + 1
rsInvoiceNumber.Update
rsInvoiceNumber.Close
Set rsInvoiceNumber = Nothing

' close connection
Set db = Nothing
0
Comment
Question by:illion
3 Comments
 
LVL 11

Expert Comment

by:phileoca
Comment Utility
Set rsInvoice = db.OpenRecordset("DELETE Invoice.* FROM Invoice")

?????
try this:
Set rsInvoice = db.OpenRecordset("DELETE * FROM Invoice")
0
 
LVL 3

Accepted Solution

by:
Section37 earned 125 total points
Comment Utility
Use OpenRecordset for Select statements, for Insert, Update, and Delete try using Execute, ie.

Set rsInvoice = db.Execute("DELETE * FROM Invoice")

-or-

CurrentDb.Execute("DELETE * FROM Invoice")

Shouldn't have an error with that one.
0
 
LVL 50

Expert Comment

by:Steve Bink
Comment Utility
From the VB help file for the OpenRecordset method, regarding the "Source" parameter:

A String specifying the source of the records for the new Recordset. The source can be a table name, a query name, or
an SQL statement that returns records. For table-type Recordset objects in Microsoft Jet databases, the source can only
be a table name          ^^^^^^^^^^
                   
DELETE queries are action queries.  The most you can hope to return is the number of rows affected.  If you need to clear the table, use this code instead:

CurrentDB.Execute "DELETE * FROM Invoice"
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now