Beste oplosser,
Ik heb al vele uren geprobeerd om mijn onafhankelijk formulier te kunnen filteren met behulp van ADO recordset.
Het filteren lukt op zich wel goed, maar de voornamen staan niet gesorteerd. Probeer eens bab in te tikken in de inputbox om dus vervolgens op achternaam Babba te filteren.
In venster direct - vba editor staan die wel gesorteerd.
Private Sub cmdFindContactName_Click()
Dim rst As ADODB.Recordset
Dim cn As ADODB.Connection
'Gebruik een ADO connectie met DAO werkt dit niet
Set cn = CurrentProject.AccessConnection
'Maak een nieuwe instantie van de ADO Recordset class
'en stel de eigenschappen in
Set rst = New ADODB.Recordset
With rst
Set .ActiveConnection = cn
.Source = "tblPatiënten"
.LockType = adLockOptimistic
.CursorType = adOpenKeyset
rst.CursorLocation = adUseClient
rst.Sort = "achternaam ASC, voornaam ASC"
'rst.Sort = "voornaam DESC" 'DESC, ASC
.Open
End With
If rst.RecordCount = 0 Then
MsgBox "No entry found.", vbInformation
Exit Sub
Else
End If
Forms!tblPatiënten.RecordSource = ""
Forms!tblPatiënten.RecordSource = "tblPatiënten"
'rst.MoveFirst
Me.FilterOn = False
Dim strAntw As String
strAntw = InputBox("geef deel van naam op")
strAntw = strAntw
'rst.Filter = "achternaam like 'bab*'"
rst.Filter = "achternaam Like '" & strAntw & "*'"
Me.Filter = rst.Filter
Me.FilterOn = True
Dim f As Form, c1 As Control, c2 As Control, c3 As Control, c4 As Control, c5 As Control, c6 As Control
'DoCmd.OpenForm "tblPatiënten" 'openen van het formulier met een macroactie
Set f = Forms![tblPatiënten]
Set c1 = f!PatiëntID 'het veld PatiëntID wordt in de variabele c1 gestockeerd
Set c2 = f!voornaam 'het veld voornaam wordt in de variabele c2 gestockeerd
Set c3 = f!tussenvoegsel
Set c4 = f!achternaam
Set c5 = f!geboortedatum
Set c6 = f!geslacht
c1.ControlSource = "PatiëntID"
c2.ControlSource = "voornaam"
c3.ControlSource = "tussenvoegsel"
c4.ControlSource = "achternaam"
c5.ControlSource = "geboortedatum"
c6.ControlSource = "geslacht"
c1.Locked = True
c2.Locked = True
c3.Locked = True
c4.Locked = True
c5.Locked = True
c6.Locked = True
Do While Not rst.EOF
Debug.Print rst!achternaam, rst!voornaam
'c2 = rst!voornaam
'MsgBox rst!voornaam
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
cn.Close
Set cn = Nothing
End Sub
Voorbeeldje in bijlage in .mdb
Vriendelijke groeten,
Diezel