Excel vba userform trying to filter ado recordset

Don Quixote

New Member
Joined
Feb 2, 2025
Messages
8
Office Version
  1. 2021
Platform
  1. Windows
I have an excel vba userform from which I connect to an adodb (ms access), But I am trying to filter on the date (Datum) field.

Both via sql statement or the recordset.filter method but neither seems to work.

Here is my code:

VBA Code:
Private Sub UserForm_Initialize()

    Dim con As Object
    Dim rs As Object
    Dim db As String
    Dim sql As String
   
    Set con = CreateObject("ADODB.Connection")
    Set rs = CreateObject("ADODB.Recordset")
    db = "Q:\Kiel Data\Blending\TEST\Base Oils.accdb"
    'db = "C:\Users\Dennis\Documents\Blending & Filling\Basis Olie Lossing\Base Oils.accdb"
    sql = "SELECT [Datum], [Bestelbon], [Productnaam], [Tank], [Losplaats], [aankomst datum], [aankomst tijd], [Transporteur], [Nummerplaat], [STAAL], [LABO], [TRANSFER], [COMPLETED], [Vertrektijd], [Opmerkingen] FROM [Planning] WHERE [Datum] = #11/12/2024#"

    con.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & db

    rs.Open sql, con

    txtBestelbon.BackColor = RGB(255, 150, 224)
    txtTransporteur.BackColor = RGB(255, 150, 224)
    txtProduct.BackColor = RGB(255, 150, 224)
    txtLosplaats.BackColor = RGB(255, 150, 224)
    txtTank.BackColor = RGB(255, 150, 224)
    EditButton.BackColor = RGB(76, 255, 0)
    SearchButton.BackColor = RGB(255, 233, 127)
    SelectButton.BackColor = RGB(255, 233, 127)
    'txtAankomstDatum = Format(Date, "dd/mm/yyyy")
    'txtAankomstUur = Format(Time, "hh:mm")

    'rs.Filter = "Datum >= #11/12/2024#"
   
    'ListBox1.ColumnCount = rs.Filter = "Datum = #11/12/2025#"
    ListBox1.ColumnCount = rs.Fields.Count
    ListBox1.ColumnWidths = "60;70;150;40;70;60;60;100;80;60;60;60;60;60;100"
    ListBox1.Column = rs.GetRows
    'ListBox1.ListIndex = 1
    ListBox1.ColumnHeads = True

End Sub

Any suggestions?

thx
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Excel, VBA and other sources work with the standard date in English format "yyyy/mm/dd", even if you visibly have another format.
 
Upvote 0

Forum statistics

Threads
1,226,405
Messages
6,190,875
Members
453,620
Latest member
ahmedshehta

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top