Solved

Delete SQL 3219

Posted on 2004-04-28
3
623 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
ID: 10942955
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
ID: 10943093
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
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"
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
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.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

912 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

19 Experts available now in Live!

Get 1:1 Help Now