Delete SQL 3219

Posted on 2004-04-28
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![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
            Set rsLocation = Nothing
            iFrom = rsHotel!Direction
        End If

        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
            Set rsLocation = Nothing
            iTo = rsHotel!Direction
        End If
        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
    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

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

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

' close connection
Set db = Nothing
Question by:illion
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
LVL 11

Expert Comment

ID: 10942955
Set rsInvoice = db.OpenRecordset("DELETE Invoice.* FROM Invoice")

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

Accepted Solution

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

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


CurrentDb.Execute("DELETE * FROM Invoice")

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

Expert Comment

by:Steve Bink
ID: 10943119
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"

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Familiarize people with the process of utilizing SQL Server functions 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 Microsoft Ac…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

710 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