Delete Record - DAO to ADO
- From: "igendreau" <ian_gendreau@xxxxxxxxxxxxxxxx>
- Date: 30 Mar 2007 19:46:20 -0700
I'm trying to clean up a database of mine, and I need to convert some
old DAO code over to ADO. When I was using DAO, I had no problem
running this script and deleting the record using rs.Delete. But when
I rework the code in ADO, it tells me I can't delete it because there
are related records in another table. Never had that problem in DAO
and I haven't touched the relationships. Ignore most of this code and
focus on the recordset "rs". Why can't I delete it??
Dim rs As New ADODB.Recordset
Dim criteria As String
Dim empts As Integer
empts = 0
If Not IsNull(Forms![View/EditPulls]![PullID]) Then
criteria = Forms![View/EditPulls]![PullID]
Else
Exit Sub
End If
rs.Open "SELECT * FROM ShipPull WHERE PullID = '" & criteria &
"'", CurrentProject.Connection, adOpenDynamic, adLockOptimistic
If rs.RecordCount <> 0 Then
rs.MoveFirst
Else
GoTo NoItems
End If
Dim prompt1 As String
Dim prompt2 As String
Dim id As String
Dim prodName As String
Dim numPulled As String
Dim ln As String
Dim inv1 As Integer
Dim inv2 As Integer
Dim totalLeft As Integer
Dim ship1 As Variant
Dim ship2 As Variant
ln = Chr(13) & Chr(10)
Do Until rs.EOF
ship1 = 0
ship2 = 0
id = rs.Fields("ProductID")
prodName = rs.Fields("ProductName")
numPulled = CStr(rs.Fields("Quantity"))
inv1 = rs.Fields("Quantity1")
inv2 = rs.Fields("Quantity2")
prompt1 = "Pull from " & loc1 & ":" & ln & Chr(10) & "Product
ID: " & id & ln & prodName & ln & "Number Pulled: " & numPulled
prompt2 = "Pull from " & loc2 & ":" & ln & Chr(10) & "Product
ID: " & id & ln & prodName & ln & "Number Pulled: " & numPulled
'
If CInt(numPulled) <= (inv1) Then '+inv2
GetShip1:
ship1 = InputBox(prompt1, "Ship Product", numPulled)
If ship1 = "" Or Not (IsNumeric(ship1)) Then
MsgBox "Invalid Entry"
GoTo GetShip1
End If
rs.Fields("Quantity1") = rs.Fields("Quantity1") -
ship1
rs.Fields("Quantity2") = rs.Fields("Quantity2") -
ship2
rs.Update
Dim strSQL
Dim Today As Variant
Dim rsHistory As ADODB.Recordset
Set rsHistory = New ADODB.Recordset
rsHistory.Open "SELECT * FROM History",
CurrentProject.Connection, adOpenDynamic, adLockOptimistic
With rsHistory
.AddNew
.Fields("PullID") = "'" & rs.Fields("PullID") &
"'"
.Fields("ProductID") = rs.Fields("ProductID")
.Fields("Quantity") = ship1
.Fields("ProductName") = "'" &
rs.Fields("ProductName") & "'"
.Fields("Description") = "'" &
rs.Fields("Description") & "'"
.Fields("Category") = "'" & rs.Fields("Category")
& "'"
.Fields("ShipDate") = Date
.Update
End With
rs.Delete
Me.Refresh
.
- Follow-Ups:
- Re: Delete Record - DAO to ADO
- From: Tom van Stiphout
- Re: Delete Record - DAO to ADO
- Prev by Date: Cleaning Up Access
- Next by Date: Re: Cleaning Up Access
- Previous by thread: Cleaning Up Access
- Next by thread: Re: Delete Record - DAO to ADO
- Index(es):
Relevant Pages
|