NikkiSpencer
03-27-2012, 03:51 AM
Hi :hi:
I have set up a class that gets data from an MS Access query passing parameters into query to return relevant records to Excel - this all works perfectly - even using wildcards (e.g. S%) - however I want to be able to pass a parameter using logical OR e.g.
following works fine:
LSIP.NewQuery "qForTemplate_PC_Main_Number"
LSIP.AddParamater "@pSection", "PC Primary"
LSIP.AddParamater "@pLevel", "School"
LSIP.AddParamater "@pLevelName", "04047"
LSIP.ImportDataToWorksheet Range("rngPC_NOR")
But what I WANT to do is something like:
LSIP.AddParameter "@pLevelName", "04047" OR "04036"
but obviously this treats the whole thing like text and returns no records.
I've tried:
"04047 OR 04036"
"'04047' OR '04036'"
etc. but no joy.
Is it possible to pass an OR so in effect two or more parameters can be passed to query?
Many thanks for any help!
By the way the LSIP Object pretty much uses the following code to add attributes (the attributes are added as a collection):
Public Sub ImportDataToWorksheet(rTargetRange As Range)
Dim rs As New ADODB.Recordset
Dim cmd As New ADODB.Command
Dim o As LSIPParam
cmd.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sDBPathAndName
cmd.CommandType = adCmdStoredProc
cmd.CommandText = sQueryName
' Set parameters
For Each o In oParams
cmd.Parameters.append cmd.createParameter(o.GetParam, adVarChar, adParamInput, 50, o.GetParamValue)
Next
rs.Open cmd
rTargetRange.ClearContents
rTargetRange.Range("a1").CopyFromRecordset rs
rs.Close
Set rs = Nothing
Set cmd = Nothing
End Sub
Nikki x
I have set up a class that gets data from an MS Access query passing parameters into query to return relevant records to Excel - this all works perfectly - even using wildcards (e.g. S%) - however I want to be able to pass a parameter using logical OR e.g.
following works fine:
LSIP.NewQuery "qForTemplate_PC_Main_Number"
LSIP.AddParamater "@pSection", "PC Primary"
LSIP.AddParamater "@pLevel", "School"
LSIP.AddParamater "@pLevelName", "04047"
LSIP.ImportDataToWorksheet Range("rngPC_NOR")
But what I WANT to do is something like:
LSIP.AddParameter "@pLevelName", "04047" OR "04036"
but obviously this treats the whole thing like text and returns no records.
I've tried:
"04047 OR 04036"
"'04047' OR '04036'"
etc. but no joy.
Is it possible to pass an OR so in effect two or more parameters can be passed to query?
Many thanks for any help!
By the way the LSIP Object pretty much uses the following code to add attributes (the attributes are added as a collection):
Public Sub ImportDataToWorksheet(rTargetRange As Range)
Dim rs As New ADODB.Recordset
Dim cmd As New ADODB.Command
Dim o As LSIPParam
cmd.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sDBPathAndName
cmd.CommandType = adCmdStoredProc
cmd.CommandText = sQueryName
' Set parameters
For Each o In oParams
cmd.Parameters.append cmd.createParameter(o.GetParam, adVarChar, adParamInput, 50, o.GetParamValue)
Next
rs.Open cmd
rTargetRange.ClearContents
rTargetRange.Range("a1").CopyFromRecordset rs
rs.Close
Set rs = Nothing
Set cmd = Nothing
End Sub
Nikki x