Hi All,
Here is my VBA Code , and i am trying to call a commond to open a query with certain parameter values and then with those specified parameters open a recordset. The errors I seem to be getting are as follows:
"Parameter object is improperly defined. Inconsistent or incomplete information was provided."
When I add in the Casting to a String lines to cast the parmeter to String I get the following:
"Item cannont be found in the collection corresponding to the requested name or ordinal"
Has any one got any ideas, please, thanks.
Dim sSql 'As String
Dim cn As New ADODB.Connection
Dim rstReportDetails As New ADODB.RecordSet
Dim cmd As ADODB.Command
'create a paramter to hold all values
Dim ProdId As ADODB.Parameter
Dim CompId As ADODB.Parameter
Dim AppNo As ADODB.Parameter
'set values
Set cn = CurrentProject.Connection
Set cmd = New ADODB.Command
'get the command object from the query
With cmd
.ActiveConnection = cn
.CommandText = "Select * From qryRptDetails" 'THIS IS A QUERY WITH IN MY FRONT END DB
.CommandType = adCmdText
Set ProdId = .CreateParameter("par1")
Set CompId = .CreateParameter("par2")
Set AppNo = .CreateParameter("par3")
'par1 = CStr(cmd.Parameters("par1"
))
'par2 = CStr(cmd.Parameters("par2"
))
'par3 = CStr(cmd.Parameters("par3"
))
.Parameters.Append ProdId
.Parameters.Append CompId
.Parameters.Append AppNo
' Set ProdId = cmd.Parameters("Forms!crpP
roduct!App
ProductId"
)
' Set CompId = cmd.Parameters("Forms!crpP
roducts!co
mCompany")
'Set AppNo = cmd.Parameters("Forms!crpP
roducts!tx
tAppendixN
o")
'.Parameters("par1") = Forms!crpProducts!AppProdu
ctId
'.Parameters("par2") = Forms!crpProducts!comCompa
ny
'.Parameters("par3") = Forms!crpProducts!txtAppen
dixNo
par1.Value = Forms!crpProducts!AppProdu
ctId
par2.Value = Forms!crpProducts!comCompa
ny
par3.Value = Forms!crpProducts!txtAppen
dixNo
'Execute
End With
'setting it to a record set
rstReportDetails.Open cmd
Here is my Access Query that I want to call with in my VBA Code, it is looking for three parametes from the a form.
PARAMETERS Forms!crpProducts!AppProdu
ctId Long, Forms!crpProducts!comCompa
ny Long, Forms!crpProducts!txtAppen
dixNo Long;
SELECT DISTINCT crpProducts.crpProduct_ID AS ProductID, crpProducts.crpProduct_Com
panyID AS CompanyID, crpProducts.crpProduct_Des
cription, crpProducts.crpProduct_Act
ivityDate,
crpProducts.crpProduct_App
endixNo AS AppendixNo, crpProductTypes.crpProduct
Type_Name,
UnitCategory2Values.unitCa
t2Name, crpProductLicenseTypes.crp
ProductLic
enseType_c
rpLicenseT
ypeID, crpLicenseTypes.crpLicense
Type_Name,
crpProducts.crpProduct_Agr
eementDate
, crpProducts.crpProduct_IsL
icensed, crpProducts.crpProduct_Rev
isedDate, tblPersonnel.Codes, People.PeopleEmail AS Email
FROM (((((crpProductTypes INNER JOIN crpProducts ON crpProductTypes.crpProduct
Type_ID=cr
pProducts.
crpProduct
_crpProduc
tTypeID) INNER JOIN crpProductLicenseTypes ON crpProducts.crpProduct_ID=
crpProduct
LicenseTyp
es.crpProd
uctLicense
Type_crpPr
oductID) INNER JOIN UnitCategory2Values ON crpProductTypes.crpProduct
Type_Categ
ory2=UnitC
ategory2Va
lues.unitC
at2ID) INNER JOIN crpLicenseTypes ON crpProductLicenseTypes.crp
ProductLic
enseType_c
rpLicenseT
ypeID=crpL
icenseType
s.crpLicen
seType_ID)
INNER JOIN tblPersonnel ON crpProducts.crpProduct_Com
panyID=tbl
Personnel.
CompanyID)
INNER JOIN People ON tblPersonnel.PeopleId=Peop
le.PeopleI
d
WHERE (((crpProducts.crpProduct_
ID)=(Forms
!crpProduc
ts!AppProd
uctId)) And ((crpProducts.crpProduct_C
ompanyID)=
(Forms!crp
Products!c
omCompany)
) And ((crpProducts.crpProduct_A
ppendixNo)
=(Forms!cr
pProducts!
txtAppendi
xNo)) And ((crpProducts.crpProduct_I
sLicensed)
=True) And ((tblPersonnel.Codes) Like "%'L'%"))
ORDER BY crpProducts.crpProduct_Com
panyID;