wildcard search a Access DB

bobaol

Board Regular
Joined
Jun 3, 2002
Messages
188
Office Version
  1. 365
  2. 2003 or older
Platform
  1. Windows
Hi, I want to do a wildcard search of a MS Access DB using a value in Excel in cell A1. In the example below, I am trying to find "%4605%". The code below works perfectly for %4605%, but the value will not always be %4605%. Sometimes the value is different.

I want to know how to search based on the value in cell A1. I am using Access11(2003) and Excel11(2003). Thanks in advance.
---------------------------------------------
Sub Macro05_wildcard_search()
Application.Goto Reference:="R1C1"
Application.Goto Reference:="R1C6"
With ActiveSheet.QueryTables.Add(Connection:=Array(Array( _
"ODBC;DSN=MS Access Database;DBQ=C:\TEMP\New Folder\2004_01.mdb;DefaultDir=C:\TEMP\New Folder;DriverId=281;FIL=MS Access;MaxBufferSiz" _
), Array("e=2048;PageTimeout=5;")), Destination:=ActiveCell)
.CommandText = Array( _
"SELECT `2004_01`.Field1, `2004_01`.Field2" & Chr(13) & "" & Chr(10) & "FROM `C:\TEMP\New Folder\2004_01`.`2004_01` `2004_01`" & Chr(13) & "" & Chr(10) & "WHERE (`2004_01`.Field2 Like '%4605%')" _
)
.Name = "Query from MS Access Database"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
Application.Goto Reference:="R1C1"
End Sub
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Sorry, I don't understand. most likely my fault. I want to use A1 everytime, without being prompted to input A1 in an Input Box. I was hoping to change this statement "WHERE (`2004_01`.Field2 Like '%4605%')" to something like this "WHERE (`2004_01`.Field2 Like range("a1:a1".value)". I want to be able to do it in VB and not SQL because I don't know SQL and I want to add additional code in VB once I get this one issue figured out. Thanks again.
 
Upvote 0
Sure,

That person didn't want a pop-up either. ;)

But just set up the pop intitially, then make the changes in the thread as described, right-clicking on the query and changing the Paramater. Once you do this, the query changes the paramater from the pop-up to the cell you point to.
 
Upvote 0

Forum statistics

Threads
1,214,861
Messages
6,121,969
Members
449,059
Latest member
oculus

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