bobaol
Board Regular
- Joined
- Jun 3, 2002
- Messages
- 188
- Office Version
- 365
- 2003 or older
- Platform
- 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
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