Filter results from access data base to show in Listbox

owen4512

Board Regular
Joined
Dec 10, 2014
Messages
71
Hi all,

I currently have a userform that allows the user to input data in excel and the data will copy into an access data base. I currently have a field in access labeled "FOLLOWUPS". This field will only contain "Yes" or "No" and i'm looking to create a macro that will search this field and return all results for "Yes" and list them in "Listbox1" Here's what i've got so far but i keep getting a syntax error on the line highlighted in red. Any help is always greatly appreciated :)

VBA Code:
Private connect As Object, rs As Object

Sub connection()
Set connect = CreateObject("adodb.connection")
#If VBA7 And Win64 Then
connect.Open "provider=microsoft.ace.oledb.12.0;data source=" & ThisWorkbook.Path & "\Customer Tracker.mdb"
#Else
connect.Open "provider=microsoft.jet.oledb.4.0;data source=" & ThisWorkbook.Path & "\Customer Tracker.mdb"
#End If
End Sub


Private Sub CommandButton6_Click()
Set connect = CreateObject("adodb.connection")
Set rs = CreateObject("adodb.recordset")
Dim Followup As String

Followup = "YES"

Call connection
[COLOR=rgb(226, 80, 65)]    rs.Open "select * from [CUSTOMER_DATA] WHERE [CUSTOMER_DATA].FOLLOWUPS SHOW '" & Followup & "%'", connect, 1, 1[/COLOR]
With Listbox1
    .RowSource = Empty
    .ColumnCount = 15
    .ColumnWidths = "30;30"
    .Column = rs.getrows
End With
    rs.Close
Set rs = Nothing
If TextBox1.Value = Empty Then
Listbox1.Clear
End If
End Sub
 
doesnt look like the vba copied over properly so please refer to the below;

VBA Code:
Private connect As Object, rs As Object

Sub connection()
Set connect = CreateObject("adodb.connection")
#If VBA7 And Win64 Then
connect.Open "provider=microsoft.ace.oledb.12.0;data source=" & ThisWorkbook.Path & "\Customer Tracker.mdb"
#Else
connect.Open "provider=microsoft.jet.oledb.4.0;data source=" & ThisWorkbook.Path & "\Customer Tracker.mdb"
#End If
End Sub

Private Sub CommandButton6_Click()
Set connect = CreateObject("adodb.connection")
Set rs = CreateObject("adodb.recordset")
Dim Followup As String

Followup = "YES"

Call connection
    rs.Open "select * from [CUSTOMER_DATA] WHERE [CUSTOMER_DATA].FOLLOWUPS SHOW '" & Followup & "%'", connect, 1, 1
With Listbox1
    .RowSource = Empty
    .ColumnCount = 15
    .ColumnWidths = "30;30"
    .Column = rs.getrows
End With
'Call date_format
    rs.Close
Set rs = Nothing
If TextBox1.Value = Empty Then
Listbox1.Clear
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,226,798
Messages
6,193,062
Members
453,773
Latest member
bclever07

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