I am not the greatest when it comes to properly writing error handlers, but have been trying to improve on it and get them added into every module/code that could potentially fail. However, on this particular one I am not too sure how to correctly handle it.
How would I correctly error handler this if there no record exist yet? I would still need the code to complete and not just out right exit. Or it might not need an handler and just another line or two on what to do if record count is zero. Could anyone offer some wisdom on this? This is also just a chunk of the code. The entire routine more or less does the same thing, just for different records. I can post the entire thing if need be.
Code:
Set rstAdd = CurrentDb.OpenRecordset("Select * From tblContractorJob Where JobID = " & OldId & "")
Set rst = rstAdd.Clone
If rstAdd.RecordCount > 0 Then
rstAdd.MoveLast
rstAdd.MoveFirst
End If
Count = rstAdd.RecordCount
For Item = 1 To Count
With rstAdd
.AddNew
For Each fld In .Fields
With fld
If .Attributes And dbAutoIncrField Then
' Skip Autonumber or GUID field.
ElseIf .Name = "JobID" Then
' Skip master/child field.
.Value = NewId
ElseIf .Name = "TypeID" Then
Set rstDrawingType = CurrentDb.OpenRecordset("Select * From tblFixtureTypes Where TypeID = " & rst!TypeID & " and JobID = " & OldId & "")
Set rstTypeID = CurrentDb.OpenRecordset("Select * From tblFixtureTypes Where TypeName = '" & rstDrawingType!TypeName & "' and JobID = " & NewId & "")
.Value = rstTypeID.Fields("TypeID").Value
Else
.Value = rst.Fields(.Name).Value
End If
End With
Next
.Update
End With
rst.MoveNext
Next
How would I correctly error handler this if there no record exist yet? I would still need the code to complete and not just out right exit. Or it might not need an handler and just another line or two on what to do if record count is zero. Could anyone offer some wisdom on this? This is also just a chunk of the code. The entire routine more or less does the same thing, just for different records. I can post the entire thing if need be.