下列代碼是一個(gè)例程,將行來源設(shè)置為這個(gè)函數(shù):
Public Function valueList(ctl As Control, _
varID As Variant, _
lngRow As Long, _
lngCol As Long, _
intCode As Integer) As Variant
Dim varRetVal As Variant
Dim strField As String
Dim strField As String
Dim strSQL As String
Dim strList As String
Dim intLoopRow As Integer
Dim intLoopCol As Integer
Dim cnn As ADODB.Connection
Dim RST As ADODB.Recordset
Static svarArray() As Variant
Static sintRows As Integer
Static sintCols As Integer
On Error GoTo Proc_err
Select Case intCode
Case acLBInitialize
On Error Resume Next
intLoopRow = Ubound(svarArray)
If Err <> 0 Then
On Error GoTo Proc_err
'populate the customer recordset
Set cnn = New ADODB.Connection
cnn.Provider = "Microsoft.Jet.OLEDB.4.0"
cnn.Properties("Data Source") = CurrentProject.Path & "\data share\data.dat"
cnn.Properties("Jet OLEDB:Database Password") = "123456789222"
cnn.Open
' With cnn
'.Provider = "Microsoft.Jet.OLEDB.4.0"
'this gets stored values from the only
'local table to allow flexibility
'.ConnectionString = CurrentProject.Path & "\data.dat" 'should be changed
'.Properties("Jet OLEDB:Database Password") = "123456789222"
'.Open
'End With
Set RST = New ADODB.Recordset
With RST
.ActiveConnection = cnn
.Source = "select usysuser.userid,usysuser.username from usysuser" 'should be changed
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.LockType = adLockReadOnly
.Open , , , , adCmdText
.MoveLast
sintRows = .RecordCount
.MoveFirst
sintCols = .Fields.Count
End With 'rst
Set cnn = Nothing
Public Function valueList(ctl As Control, _
varID As Variant, _
lngRow As Long, _
lngCol As Long, _
intCode As Integer) As Variant
Dim varRetVal As Variant
Dim strField As String
Dim strField As String
Dim strSQL As String
Dim strList As String
Dim intLoopRow As Integer
Dim intLoopCol As Integer
Dim cnn As ADODB.Connection
Dim RST As ADODB.Recordset
Static svarArray() As Variant
Static sintRows As Integer
Static sintCols As Integer
On Error GoTo Proc_err
Select Case intCode
Case acLBInitialize
On Error Resume Next
intLoopRow = Ubound(svarArray)
If Err <> 0 Then
On Error GoTo Proc_err
'populate the customer recordset
Set cnn = New ADODB.Connection
cnn.Provider = "Microsoft.Jet.OLEDB.4.0"
cnn.Properties("Data Source") = CurrentProject.Path & "\data share\data.dat"
cnn.Properties("Jet OLEDB:Database Password") = "123456789222"
cnn.Open
' With cnn
'.Provider = "Microsoft.Jet.OLEDB.4.0"
'this gets stored values from the only
'local table to allow flexibility
'.ConnectionString = CurrentProject.Path & "\data.dat" 'should be changed
'.Properties("Jet OLEDB:Database Password") = "123456789222"
'.Open
'End With
Set RST = New ADODB.Recordset
With RST
.ActiveConnection = cnn
.Source = "select usysuser.userid,usysuser.username from usysuser" 'should be changed
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.LockType = adLockReadOnly
.Open , , , , adCmdText
.MoveLast
sintRows = .RecordCount
.MoveFirst
sintCols = .Fields.Count
End With 'rst
Set cnn = Nothing