home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 6 Unleashed…sional Reference Edition) / Visual_Basic_6_Unleashed_Professional_Reference_Edition_Sams_1999.iso / Source / CHAP08 / 309X0806.TXT < prev    next >
Encoding:
Text File  |  1998-06-17  |  1.9 KB  |  57 lines

  1.  
  2. Private Sub UserControl_GetDataMember(DataMember As String, _
  3.     Data As Object)
  4.  
  5.     On Error GoTo ErrorHandler
  6.  
  7.     If (cnMain Is Nothing) Or (rsMain Is Nothing) Then
  8.         ' If no ConnectionString has been specified,
  9.         ' show an error and exit this procedure.
  10.         If mstrConnectionString = "" Then
  11.             MsgBox "Please specify a value for the " _
  12.                 & "ConnectionString property.", _
  13.                 vbInformation, Ambient.DisplayName
  14.             Exit Sub
  15.         End If
  16.         ' If no RecordSource has been specified, show
  17.         ' an error and exit this procedure.
  18.         If mstrRecordSource = "" Then
  19.             MsgBox "Please specify a value for the " _
  20.                 & "RecordSource property.", _
  21.                 vbInformation, Ambient.DisplayName
  22.             Exit Sub
  23.         End If
  24.         ' Set up the ADO connection using the value
  25.         ' specified for the ConnectionString property.
  26.         Set cnMain = New ADODB.Connection
  27.         cnMain.ConnectionString = mstrConnectionString
  28.         cnMain.Open
  29.         ' Set up the ADO recordset using the value
  30.         ' specified for the RecordSource property.
  31.         Set rsMain = New ADODB.RecordSet
  32.         rsMain.Open mstrRecordSource, cnMain, _
  33.             adOpenKeyset, adLockPessimistic
  34.         rsMain.MoveFirst
  35.         ' Set the upper value limit of the hsbRecScroll
  36.         ' control to the number of records in the
  37.         ' recordset (plus one for additions).
  38.         hsbRecScroll.Max = rsMain.RecordCount + 1
  39.     Else
  40.         Set cnMain = Nothing
  41.         Set rsMain = Nothing
  42.     End If
  43.     
  44.     ' Return the recordset in the Data argument.
  45.     Set Data = rsMain
  46.     
  47.     Exit Sub
  48.  
  49. ErrorHandler:
  50.     ' An error has occurred, so display the error
  51.     ' and exit the procedure.
  52.     MsgBox "Error: " & CStr(Err.Number) _
  53.         & vbCrLf & Err.Description, vbOKOnly, _
  54.         Ambient.DisplayName
  55.     
  56. End Sub
  57.