home *** CD-ROM | disk | FTP | other *** search
-
- Private Sub UserControl_GetDataMember(DataMember As String, _
- Data As Object)
-
- On Error GoTo ErrorHandler
-
- If (cnMain Is Nothing) Or (rsMain Is Nothing) Then
- ' If no ConnectionString has been specified,
- ' show an error and exit this procedure.
- If mstrConnectionString = "" Then
- MsgBox "Please specify a value for the " _
- & "ConnectionString property.", _
- vbInformation, Ambient.DisplayName
- Exit Sub
- End If
- ' If no RecordSource has been specified, show
- ' an error and exit this procedure.
- If mstrRecordSource = "" Then
- MsgBox "Please specify a value for the " _
- & "RecordSource property.", _
- vbInformation, Ambient.DisplayName
- Exit Sub
- End If
- ' Set up the ADO connection using the value
- ' specified for the ConnectionString property.
- Set cnMain = New ADODB.Connection
- cnMain.ConnectionString = mstrConnectionString
- cnMain.Open
- ' Set up the ADO recordset using the value
- ' specified for the RecordSource property.
- Set rsMain = New ADODB.RecordSet
- rsMain.Open mstrRecordSource, cnMain, _
- adOpenKeyset, adLockPessimistic
- rsMain.MoveFirst
- ' Set the upper value limit of the hsbRecScroll
- ' control to the number of records in the
- ' recordset (plus one for additions).
- hsbRecScroll.Max = rsMain.RecordCount + 1
- Else
- Set cnMain = Nothing
- Set rsMain = Nothing
- End If
-
- ' Return the recordset in the Data argument.
- Set Data = rsMain
-
- Exit Sub
-
- ErrorHandler:
- ' An error has occurred, so display the error
- ' and exit the procedure.
- MsgBox "Error: " & CStr(Err.Number) _
- & vbCrLf & Err.Description, vbOKOnly, _
- Ambient.DisplayName
-
- End Sub
-