VERSION 5.00 Begin VB.Form frmAdo Caption = "ADO oefening" ClientHeight = 4920 ClientLeft = 60 ClientTop = 450 ClientWidth = 5730 LinkTopic = "Form1" ScaleHeight = 4920 ScaleWidth = 5730 StartUpPosition = 3 'Windows Default Begin VB.CommandButton cmdChangeRecordSource Caption = "Change Source" Height = 375 Left = 240 TabIndex = 5 Top = 4440 Width = 2175 End Begin VB.TextBox txtJumpNumber Height = 285 Left = 4200 TabIndex = 4 Text = "2" Top = 3960 Width = 495 End Begin VB.CommandButton cmdJumpRec Caption = "Jump" Height = 495 Left = 3000 TabIndex = 3 Top = 3840 Width = 975 End Begin VB.CommandButton cmdNextRec Caption = ">>" Height = 495 Left = 1440 TabIndex = 2 Top = 3840 Width = 975 End Begin VB.CommandButton cmdPreviousRec Caption = "<<" Height = 495 Left = 240 TabIndex = 1 Top = 3840 Width = 975 End Begin VB.ListBox lstResult Height = 3375 Left = 120 TabIndex = 0 Top = 120 Width = 5415 End End Attribute VB_Name = "frmAdo" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Dim cn As ADODB.Connection Dim rs As ADODB.Recordset Private Sub cmdChangeRecordSource_Click() Dim sAnswer As String Dim sDefault As String On Error GoTo ErrorHandler sDefault = "Select * From Authors" sAnswer = InputBox("Geef een nieuwe source op aub...", "New source", sDefault) If Not sAnswer = vbNullString Then 'Bestaande recordset sluiten rs.Close 'Source wijzigen rs.Source = sAnswer 'Recordset opnieuw openen rs.Open DisplayCurrentRecord End If ExitHandler: Exit Sub ErrorHandler: MsgBox Error$ Resume ExitHandler End Sub Private Sub cmdJumpRec_Click() On Error GoTo ErrorHandler rs.Move Val(txtJumpNumber.Text) DisplayCurrentRecord ExitHandler: Exit Sub ErrorHandler: MsgBox Error$ Resume ExitHandler End Sub Private Sub cmdNextRec_Click() On Error GoTo ErrorHandler rs.MoveNext DisplayCurrentRecord ExitHandler: Exit Sub ErrorHandler: MsgBox Error$ Resume ExitHandler End Sub Private Sub cmdPreviousRec_Click() On Error GoTo ErrorHandler rs.MovePrevious DisplayCurrentRecord ExitHandler: Exit Sub ErrorHandler: MsgBox Error$ Resume ExitHandler End Sub Private Sub Form_Load() On Error GoTo ErrorHandler ' Open een verbinding Set cn = New ADODB.Connection cn.ConnectionString = GetConnectionString2 cn.Open ' Open een recordset Set rs = New ADODB.Recordset rs.ActiveConnection = cn rs.Source = GetSqlStatement rs.CursorType = adOpenDynamic rs.Open ' Tonen eerste record DisplayCurrentRecord ExitHandler: Exit Sub ErrorHandler: MsgBox Error$ Resume ExitHandler End Sub Private Sub DisplayCurrentRecord() Dim i As Integer Dim sTemp As String Dim iFields As Integer On Error GoTo ErrorHandler 'Kijken of recordset niet aan beginmarker staat If rs.BOF Then rs.MoveFirst 'Kijken of recordset niet aan eindmarker staat If rs.EOF Then rs.MoveLast 'Leegmaken listbox lstResult.Clear 'Tellen hoeveel velden de recordset bevatµ iFields = rs.Fields.Count 'Opvullen listbox rekening houdend met het variabel aantal velden in een recordset For i = 0 To iFields - 1 sTemp = rs.Fields(i).Name & " : " & rs.Fields(i).Value lstResult.AddItem sTemp Next i ExitHandler: Exit Sub ErrorHandler: MsgBox Error$ Resume ExitHandler End Sub