Hi,
I want to Delete only FK on the many side first and the record on the one side by one click of a button. I wrote some code which sometimes works and sometimes it does not!!
I wonder if any one have a better idea or doing this please?
tblRCC is the one side of the relationship and tblPhase is the many side.
Any help will be very much appreciated.
B
I want to Delete only FK on the many side first and the record on the one side by one click of a button. I wrote some code which sometimes works and sometimes it does not!!
I wonder if any one have a better idea or doing this please?
Code:
Private Sub Delete_Click()
Dim db As DAO.Database, rs As DAO.Recordset
Dim n As Integer, i As Integer
Dim vStart As Integer
Dim vEnd As Integer
Dim vSite As Integer
Dim vRCCID As Integer
vSite = Forms![frmSite].Form![SiteID]
vRCCID = Forms![frmSite]![Roads Construction Consent].Form![RCCID]
vStart = Me.PhaseStart - 1
vEnd = Me.PhaseEnd + 1
Set db = CurrentDb
Set rs = db.OpenRecordset("tblPhase")
rs.MoveLast
n = rs.RecordCount
rs.MoveFirst
If n > 0 Then
For i = 1 To n
If rs![SiteID] = vSite Then
If rs![PhaseNumber] > vStart And rs![PhaseNumber] < vEnd Then
rs.Edit
rs![RCCID] = Null
rs.Update
End If
End If
rs.MoveNext
Next i
End If
rs.Close
db.Close
Set db = Nothing
Set rs = Nothing
'/////////////////////////////////////////////
DoCmd.RunSQL "DELETE RCCID FROM tblRCC WHERE RCCID = " & vRCCID & ""
'//////////////////////////////////////////////
End Sub
tblRCC is the one side of the relationship and tblPhase is the many side.
Any help will be very much appreciated.
B