L
Laurent M
Hello,
i got this piece of code which returns a recordset from an Access Query.
But i need this function to pass dynamicaly the name as a parameter of the
function, and then get a recordset from that.
But this code needs to add parameters from the query :
Dim adoCmd As ADODB.Command
Dim adoConn As ADODB.Connection
Dim adoRS As ADODB.Recordset
' Database connection
'sAccessDB path of the Access DB
Set adoConn = New ADODB.Connection
adoConn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" &
sAccessDB & "; USER ID=Admin; PASSWORD=;"
Set adoCmd = New ADODB.Command
With adoCmd
.ActiveConnection = adoConn
'Name of the query
.CommandText = "QueryName"
.CommandType = adCmdStoredProc
'Parameters defined in the query
.Parameters.Append .CreateParameter("pCycle", adVarChar,
adParamInput, 16, sCompSel)
.Parameters.Append .CreateParameter("pWorkDate", adDate,
adParamInput, , UpdateDate)
'Execute the query
Set adoRS = adoCmd.Execute
End With
'Close connection
Set adoRS = Nothing
Set adoCmd = Nothing
Set adoConn = Nothing
Do you know how could i get rid of lines with .Parameters or how could i
dynamicaly get those from the name of the query?
I'm stuck
Please help, thanks
i got this piece of code which returns a recordset from an Access Query.
But i need this function to pass dynamicaly the name as a parameter of the
function, and then get a recordset from that.
But this code needs to add parameters from the query :
Dim adoCmd As ADODB.Command
Dim adoConn As ADODB.Connection
Dim adoRS As ADODB.Recordset
' Database connection
'sAccessDB path of the Access DB
Set adoConn = New ADODB.Connection
adoConn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" &
sAccessDB & "; USER ID=Admin; PASSWORD=;"
Set adoCmd = New ADODB.Command
With adoCmd
.ActiveConnection = adoConn
'Name of the query
.CommandText = "QueryName"
.CommandType = adCmdStoredProc
'Parameters defined in the query
.Parameters.Append .CreateParameter("pCycle", adVarChar,
adParamInput, 16, sCompSel)
.Parameters.Append .CreateParameter("pWorkDate", adDate,
adParamInput, , UpdateDate)
'Execute the query
Set adoRS = adoCmd.Execute
End With
'Close connection
Set adoRS = Nothing
Set adoCmd = Nothing
Set adoConn = Nothing
Do you know how could i get rid of lines with .Parameters or how could i
dynamicaly get those from the name of the query?
I'm stuck
Please help, thanks