G
Guest
I am trying to perform a SQL DELETE with a JOIN on an ACCESS database but
have not been able to.
The documentation is not clear as to whether the DELETE instrucion supports
JOINS or not
Its a 2 Table problem.
'The following CommandText doesn't work
'.CommandText = "DELETE FROM TestMaterials " & _
"INNER JOIN Materials " & _
"ON Materials.MaterialID = TestMaterials.MaterialID " & _
"WHERE ((TestMaterials.ProgID = '" & SelectedProgID & "') " & _
"AND (Materials.MatName = '" & mtMaterialOrgCellValue & "'))"
By splitting the operation into 2 parts, it works
.CommandText = "SELECT MaterialID FROM Materials " & _
"WHERE MatName = '" & mtMaterialOrgCellValue & "'"
Set objRS = New ADODB.Recordset
Call OpenDisconnectedRecordset(strConnection, objRS, objCom)
With objRS
If Not .EOF Then
If Not IsNull(.Fields.Item(0).Value) Then
tMatID = CStr(.Fields.Item(0).Value)
End If
End If
End With
.CommandText = "DELETE FROM TestMaterials " & _
"WHERE ((ProgID = '" & SelectedProgID & "') " & _
"AND (MaterialID = " & tMatID & "))"
have not been able to.
The documentation is not clear as to whether the DELETE instrucion supports
JOINS or not
Its a 2 Table problem.
'The following CommandText doesn't work
'.CommandText = "DELETE FROM TestMaterials " & _
"INNER JOIN Materials " & _
"ON Materials.MaterialID = TestMaterials.MaterialID " & _
"WHERE ((TestMaterials.ProgID = '" & SelectedProgID & "') " & _
"AND (Materials.MatName = '" & mtMaterialOrgCellValue & "'))"
By splitting the operation into 2 parts, it works
.CommandText = "SELECT MaterialID FROM Materials " & _
"WHERE MatName = '" & mtMaterialOrgCellValue & "'"
Set objRS = New ADODB.Recordset
Call OpenDisconnectedRecordset(strConnection, objRS, objCom)
With objRS
If Not .EOF Then
If Not IsNull(.Fields.Item(0).Value) Then
tMatID = CStr(.Fields.Item(0).Value)
End If
End If
End With
.CommandText = "DELETE FROM TestMaterials " & _
"WHERE ((ProgID = '" & SelectedProgID & "') " & _
"AND (MaterialID = " & tMatID & "))"