Delete Record - DAO to ADO



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

.



Relevant Pages

  • Search pattern
    ... Dim strfile As String ... Dim bAddressFound As Boolean ... Dim strCurrentChar As String ...
    (comp.databases.ms-access)
  • RE: Query to DB2
    ... Since the ADO code took considerable sniffing around and piecing together, ... Extract data from a Database to Excel ... Dim cn As New ADODB.Connection ... Dim sProv As String, sDS As String, sCon As String, sTable As String, ...
    (microsoft.public.excel.programming)
  • Auto Write Name and Merge across
    ... Dim Sheetname01 As String ... Dim WeekName01 As String ...
    (microsoft.public.excel.misc)
  • Re: multiplatform (pocketPC & desktopPC) (Daniel !!)
    ... Friend Versione As String ... Public Sub GetMyConnectionPalmare() ... Dim errorMessages As String ... Private Function GetDS_Desktop(ByVal SQL As String) As DataSet ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: multiplatform (pocketPC & desktopPC) (Daniel !!)
    ... Friend Versione As String ... Public Sub GetMyConnectionPalmare() ... Dim errorMessages As String ... Private Function GetDS_Desktop(ByVal SQL As String) As DataSet ...
    (microsoft.public.dotnet.framework.compactframework)