Access.2007.VBA.Bibl..

(John Hannent) #1
& Chr$(39) & “ already used; “ _
& “please enter another category “ _
& “name”
strTitle = “Category used”
MsgBox prompt:=strPrompt, _
Buttons:=vbExclamation + vbOKOnly, _
Title:=strTitle
GoTo CategoryName
Else
.AddNew
![Category] = strCategory
.Update
strPrompt = Chr$(39) & strCategory _
& Chr$(39) & “ added to table”
strTitle = “Category added”
MsgBox prompt:=strPrompt, _
Buttons:=vbInformation + vbOKOnly, _
Title:=strTitle
Debug.Print .RecordCount _
& “ records in recordset after adding”
End If
End With
End If

ErrorHandlerExit:

Close the Recordset and Connection objects.

If Not rst Is Nothing Then
If rst.State = adStateOpen Then
rst.Close
Set rst = Nothing
End If
End If

If Not cnn Is Nothing Then
If cnn.State = adStateOpen Then
cnn.Close
Set cnn = Nothing
End If
End If

Exit Sub

ErrorHandler:
MsgBox “Error No: “ & Err.Number _
& “; Description: “ & Err.Description
Resume ErrorHandlerExit

End Sub

Part II Writing VBA Code to Exchange Data between Office Components

Free download pdf