Excel Macro to Retrieve Info from Access - SQL Query

Lee.

Board Regular
Joined
Dec 15, 2012
Messages
170
Hi,
I've wrote the following macro but get the error "Run-time error '-2147352571', Could not set the List property. Type mismatch"

I'm struggling to see where the issue lies.

The debug highlights the following line

Code:
        .List(i, 0) = rst![CALLBACK_TIME]

Here is the full macro

Code:
Private Sub ListBox1_Change()
    Dim cnn As ADODB.Connection
    Dim rst As ADODB.Recordset
    Dim fld As ADODB.Field
    Dim MyConn
    Dim i As Long
    Dim sSQL As String
    Dim search_cat As Date
    search_cat = Me.ListBox1.Value
    
    sSQL = "select Distinct(CALLBACK_TIME) from RETAINED_BANKING where CALLBACK_DATE = #" & search_cat & "# and BOOKING_STATUS = '" & Available & "'"


    Set cnn = New ADODB.Connection
    MyConn = ThisWorkbook.Path & Application.PathSeparator & "Booking_System.mdb"
    
    With cnn
        .Provider = "Microsoft.Jet.OLEDB.4.0"
        .Open MyConn
    End With


    Set rst = New ADODB.Recordset
    rst.CursorLocation = adUseServer
    rst.Open Source:=sSQL, ActiveConnection:=cnn, _
             CursorType:=adOpenForwardOnly, LockType:=adLockOptimistic, _
             Options:=adCmdText
    
    i = 0
    With Me.ListBox2
    .Clear
    Do
        .AddItem
        .List(i, 0) = rst![CALLBACK_TIME]
        i = i + 1
        rst.MoveNext
    Loop Until rst.EOF
    End With


    rst.Close
    cnn.Close
    Set rst = Nothing
    Set cnn = Nothing


End Sub

Many thanks
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Try

rst.movefirst

With Me.ListBox2
.Clear
Do
.AddItem rs.Fields(0).Value
rst.MoveNext
Loop Until rst.EOF

End With


its slow and i'm sure you can connect the recordset directly but since you want to close it this will work
 
Upvote 0
I get the same error.

It appears to be only on some dates.

I've managed to fix it though but formatting the date in American format rather than UK
Code:
    search_cat = Format(Me.ListBox1.Value, "MM/DD/YYYY")
 
Upvote 0

Forum statistics

Threads
1,223,239
Messages
6,170,947
Members
452,368
Latest member
jayp2104

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