S
sonu
Hi,
I am using adodb recorset and excel driver to query a worksheet in
excel file. When I try to use like poerator it gives me an error. Can
someone please help me. Below is my code
When I remove % and replace it with correct part number it shows the
correct results. But my part number column has more part number and I
just need to count records that contains part number I supplied.
Sub PartNumberUsage()
Dim condb As New ADODB.Connection
wk_selected = ActiveSheet.Name
wk_xtab = "MSO_Xtab"
dbpath = ActiveWorkbook.FullName
conn = "DRIVER={Microsoft Excel Driver (*.xls)}; ReadOnly=1;DBQ=" &
dbpath
condb.Open conn
Set rst = New ADODB.Recordset
Sql = "select count(" & Worksheets(wk_xtab).Range("A1").Value & ")
from [MSO_Xtab$A:iv] where Part_no = '301971%' "
Call rst.Open(Sql, condb, CursorTypeEnum.adOpenForwardOnly,
LockTypeEnum.adLockReadOnly, CommandTypeEnum.adCmdText)
Cells(ActiveCell.Row, ActiveCell.Column + 1).Value = rst(0)
Application.StatusBar = False
rst.Close
Set rst = Nothing
Set condb = Nothing
I am using adodb recorset and excel driver to query a worksheet in
excel file. When I try to use like poerator it gives me an error. Can
someone please help me. Below is my code
When I remove % and replace it with correct part number it shows the
correct results. But my part number column has more part number and I
just need to count records that contains part number I supplied.
Sub PartNumberUsage()
Dim condb As New ADODB.Connection
wk_selected = ActiveSheet.Name
wk_xtab = "MSO_Xtab"
dbpath = ActiveWorkbook.FullName
conn = "DRIVER={Microsoft Excel Driver (*.xls)}; ReadOnly=1;DBQ=" &
dbpath
condb.Open conn
Set rst = New ADODB.Recordset
Sql = "select count(" & Worksheets(wk_xtab).Range("A1").Value & ")
from [MSO_Xtab$A:iv] where Part_no = '301971%' "
Call rst.Open(Sql, condb, CursorTypeEnum.adOpenForwardOnly,
LockTypeEnum.adLockReadOnly, CommandTypeEnum.adCmdText)
Cells(ActiveCell.Row, ActiveCell.Column + 1).Value = rst(0)
Application.StatusBar = False
rst.Close
Set rst = Nothing
Set condb = Nothing