I have the following code which pulls the results of a table in Microsoft access into excel. Currently the code filters the results from within the code, however I would like to filter the results by the vaule expressed in a cell. -
Option Explicit
-
-
Sub ADO_Demo()
-
' This demo requires a reference to
-
' the Microsoft ActiveX Data Objects 2.x Library
-
-
Dim DBFullName As String
-
Dim Cnct As String, Src As String
-
Dim Connection As ADODB.Connection
-
Dim Recordset As ADODB.Recordset
-
Dim Col As Integer
-
-
Cells.Clear
-
MsgBox "This demo retrieves the data for the records in which ITEM = LEASE and DIVISION = N. AMERICA."
-
-
' Database information
-
DBFullName = ThisWorkbook.Path & "\budget.mdb"
-
-
' Open the connection
-
Set Connection = New ADODB.Connection
-
Cnct = "Provider=Microsoft.Jet.OLEDB.4.0; "
-
Cnct = Cnct & "Data Source=" & DBFullName & ";"
-
Connection.Open ConnectionString:=Cnct
-
-
' Create RecordSet
-
Set Recordset = New ADODB.Recordset
-
With Recordset
-
' Filter
-
Src = "SELECT * FROM Budget WHERE Item = 'Lease' "
-
Src = Src & "and Division = 'N. America'"
-
.Open Source:=Src, ActiveConnection:=Connection
-
-
' Write the field names
-
For Col = 0 To Recordset.Fields.Count - 1
-
Range("A1").Offset(0, Col).Value = Recordset.Fields(Col).Name
-
Next
-
-
' Write the recordset
-
Range("A1").Offset(1, 0).CopyFromRecordset Recordset
-
End With
-
Set Recordset = Nothing
-
Connection.Close
-
Set Connection = Nothing
-
End Sub
-
1 1662
Assuming the cells are on worksheet "Input", cells B1, B2. -
................
-
Src = "SELECT * FROM Budget WHERE Item = '" & ThisWorkBook.WorkSheets("Input").Range("B1") & "' "
-
Src = Src & "and Division = '" & ThisWorkBook.WorkSheets("Input").Range("B2") & "'"
-
................
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Marek Mänd |
last post by:
This posting will express my concern about the future of css3
forthcoming recommendation.
I think for long time now, that the current implementation of CSS
attribute opacity is less than usable...
|
by: CSDunn |
last post by:
Hello,
I have a problem with field filtering between an Access 2000 Project form
(the application is called CELDT), and the report that shows the results of
the filter. Both the form and the...
|
by: hazz |
last post by:
before I start filling up the first page of perhaps many pages of code with
if/then or switch:case buckets, I wanted to step back and see if there is a
better way...
I will have a table with up to...
|
by: g-fro |
last post by:
My stored procedure is below. I would like to be able to take the
delaydata.timestamp field and grab only the records during a certain
hour. How would I go about doing this? Currently I filter...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |