CursorType, LockType, EditMode Properties Example

This example demonstrates setting the CursorType and LockType properties before opening a Recordset. It also shows the value of the EditMode property under various conditions. The EditModeOutput function is required for this procedure to run.

Sub EditModeX()

	Dim rstEmployees As ADODB.Recordset
	Dim strCnn As String

	' Open recordset with data from Employee table.
	strCnn = "driver={SQL Server};server=srv;" & _
		"uid=sa;pwd=;database=pubs"
	Set rstEmployees = New ADODB.Recordset
	rstEmployees.CursorType = adOpenDynamic
	rstEmployees.LockType = adLockOptimistic
	rstEmployees.Open "Select emp_id, fname, lname FROM employee", strCnn

	' Show the EditMode property under different editing
	' states.
	With rstEmployees
		EditModeOutput "Before AddNew:", .EditMode
		.AddNew
		!emp_id = "T-T55555M"
		!fname = "temp_fname"
		!lname = "temp_lname"
		EditModeOutput "After AddNew:", .EditMode
		.Update
		EditModeOutput "After Update:", .EditMode
		.Delete
		EditModeOutput "After Delete:", .EditMode
		!fname = "test"
		EditModeOutput "After Edit:", .EditMode
		.CancelUpdate
		EditModeOutput "After CancelUpdate:", .EditMode
		.Close
	End With

End Sub

Function EditModeOutput(strTemp As String, _
	intEditMode As Integer)

	' Print report based on the value of the EditMode 
	' property.
	Debug.Print strTemp
	Debug.Print "    EditMode = ";

	Select Case intEditMode
		Case dbEditNone
			Debug.Print "dbEditNone"
		Case dbEditInProgress
			Debug.Print "dbEditInProgress"
		Case dbEditAdd
			Debug.Print "dbEditAdd"
	End Select

End Function

© 1997 Microsoft Corporation. All rights reserved. Terms of Use.