这个程序,我不会改.
只提供一下建议。用添加数据窗口时选择类生成的那个 类的代码来封装。
那个类的代码如下:你只要换成你对应的 数据生成函数就可以了。
如果你要 winscok 控件的话,你就用自定义控件的办法进行封装。自定义控件支持类的这个属性和设置
Option Explicit
Dim WithEvents adoPrimaryRS As Recordset
Private DoingRequery As Boolean
Public Event MoveComplete()
Private Sub Class_Initialize()
Dim db As Connection
Set db = New Connection
db.CursorLocation = adUseClient
db.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=F:\download\代码\server\mdb\grx.mdb;"
Set adoPrimaryRS = New Recordset
adoPrimaryRS.Open "select MediaBLOB,MediaDescription,MediaID,MediaName,MediaType from tblMedia", db, adOpenStatic, adLockOptimistic
DataMembers.Add "Primary"
End Sub
Private Sub Class_GetDataMember(DataMember As String, Data As Object)
Select Case DataMember
Case "Primary"
Set Data = adoPrimaryRS
End Select
End Sub
Private Sub adoPrimaryRS_MoveComplete(ByVal adReason As ADODB.EventReasonEnum, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
RaiseEvent MoveComplete
End Sub
Private Sub adoPrimaryRS_WillChangeRecord(ByVal adReason As ADODB.EventReasonEnum, ByVal cRecords As Long, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
'验证代码置于此处
'下列动作发生时该事件被调用
Dim bCancel As Boolean
Select Case adReason
Case adRsnAddNew
Case adRsnClose
Case adRsnDelete
Case adRsnFirstChange
Case adRsnMove
Case adRsnRequery
Case adRsnResynch
Case adRsnUndoAddNew
Case adRsnUndoDelete
Case adRsnUndoUpdate
Case adRsnUpdate
End Select
If bCancel Then adStatus = adStatusCancel
End Sub
Public Property Get EditingRecord() As Boolean
EditingRecord = (adoPrimaryRS.EditMode <> adEditNone)
End Property
Public Property Get AbsolutePosition() As Long
AbsolutePosition = adoPrimaryRS.AbsolutePosition
End Property
Public Sub AddNew()
adoPrimaryRS.AddNew
End Sub
Public Sub Delete()
adoPrimaryRS.Delete
MoveNext
End Sub
Public Sub Requery()
adoPrimaryRS.Requery
DataMemberChanged "Primary"
End Sub
Public Sub Update()
With adoPrimaryRS
.UpdateBatch adAffectAll
If .EditMode = adEditAdd Then
MoveLast
End If
End With
End Sub
Public Sub Cancel()
With adoPrimaryRS
.CancelUpdate
If .EditMode = adEditAdd Then
MoveFirst
End If
End With
End Sub
Public Sub MoveFirst()
adoPrimaryRS.MoveFirst
End Sub
Public Sub MoveLast()
adoPrimaryRS.MoveLast
End Sub
Public Sub MoveNext()
If Not adoPrimaryRS.EOF Then adoPrimaryRS.MoveNext
If adoPrimaryRS.EOF And adoPrimaryRS.RecordCount > 0 Then
Beep
'已到最后返回
adoPrimaryRS.MoveLast
End If
End Sub
Public Sub MovePrevious()
If Not adoPrimaryRS.BOF Then adoPrimaryRS.MovePrevious
If adoPrimaryRS.BOF And adoPrimaryRS.RecordCount > 0 Then
Beep
'已到最后返回
adoPrimaryRS.MoveFirst
End If
End Sub