Adde data til combobox fra en access db
Hvorfor vil dette ikke virke? Den siger at "Object Variable or With block variable not set". Fejlen sker her:------------------------------------------------------
Private Sub RytterCombo_GotFocus()
Dim ryttertmp As ADODB.Recordset
Dim sqlstr2 As String
sqlstr2 = "SELECT Navn,Rytternr FROM Deltager"
sql.SQLConn
Set ryttertmp = sql.rsSelect(sqlstr2)
Do Until ryttertmp.EOF <------------------ FEJL!!
RytterCombo.AddItem (ryttertmp("Navn") & " - " & ryttertmp("Rytternr"))
ryttertmp.MoveNext
Loop
sql.Disconnect
End Sub
-------------------------------------------------------
min sql klasse:
-------------------------------------------------------
Option Explicit
'connection variable
Dim cn As New ADODB.Connection
Dim tmp As String
Public Sub SQLConn()
cn.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & App.Path & "\data.mdb"
End Sub
Public Sub Disconnect()
'Lukker forbindelsen
cn.Close
End Sub
Public Function rsSelect(record As String) As ADODB.Recordset
'Bruges når man skal hente noget fra en tabel
Dim rs As ADODB.Recordset
tmp = record
'initialiserer recordset
Set rs = New ADODB.Recordset
'Åben recordset
rs.Open tmp, cn
End Function
Public Sub rsExecute(record As String)
'Bruges når man skal indsætte,update eller slette noget fra en tabel.
Dim rs As ADODB.Recordset
tmp = record
'initialiserer recordset
Set rs = New ADODB.Recordset
'Åben recordset
rs.Open tmp, cn
End Sub
------------------------------------------------------