Hi,
I have a querydef with one input parameter.
Set myDb = CurrentDb()
Set rs = Nothing
Set qdf = myDb.QueryDefs("qryAssetDetails_lessBank")
qdf.Parameters(0) = Me.cboChannel
strName = "tblTempRS"
strIn = qdf.SQL
strOut = Replace(strIn, "From", "INTO " & strName & " FROM")
Debug.Print strOut
qdf.Execute strOut
The execute gives a 'data type conversion error' (3421). The SQL executes OK in Access query window.
Any ideas?
SQL:
SELECT dbo_ASSET.ASSET_ID, dbo_ASSET_COMPONENT.ASSET_COMPONENT_ID, dbo_ASSET.ASSET_CODE, dbo_ASSET.RUNNING_DISTANCE, "" AS Bank, dbo_COMPONENT_TYPE.COMPONENT_TYPE_DESC, dbo_CONDITION.RATING, dbo_ASSET.OWNERSHIP, dbo_ASSET.NUMBER_ON_PLAN
INTO tblTempRS FROM ((dbo_CONDITION INNER JOIN (((dbo_ASSET INNER JOIN dbo_ASSET_ASSET_GROUP ON dbo_ASSET.ASSET_ID=dbo_ASSET_ASSET_GROUP.ASSET_ID) INNER JOIN dbo_ASSET_GROUP ON dbo_ASSET_ASSET_GROUP.ASSET_GROUP_ID=dbo_ASSET_GROUP.ASSET_GROUP_ID) INNER JOIN dbo_ASSET_COMPONENT ON dbo_ASSET.ASSET_ID=dbo_ASSET_COMPONENT.ASSET_ID) ON (dbo_CONDITION.ASSET_COMPONENT_ID=dbo_ASSET_COMPONENT.ASSET_COMPONENT_ID) AND (dbo_CONDITION.ASSET_ID=dbo_ASSET_COMPONENT.ASSET_ID)) INNER JOIN dbo_ASSET_TYPE ON dbo_ASSET.ASSET_TYPE_CODE=dbo_ASSET_TYPE.ASSET_TYPE_CODE) INNER JOIN dbo_COMPONENT_TYPE ON dbo_ASSET_COMPONENT.COMPONENT_TYPE_CODE=dbo_COMPONENT_TYPE.COMPONENT_TYPE_CODE
WHERE (((dbo_ASSET.ASSET_NAME)=Forms!frmAssetLifeMain!cboChannel) And ((dbo_ASSET.ASSET_TYPE_CODE)="ST" Or (dbo_ASSET.ASSET_TYPE_CODE)="CH") And ((dbo_ASSET_GROUP.SHORT_NAME)="MID Irrigation"))
ORDER BY dbo_ASSET.ASSET_NAME, dbo_ASSET.RUNNING_DISTANCE;SELECT dbo_ASSET.ASSET_ID, dbo_ASSET_COMPONENT.ASSET_COMPONENT_ID, dbo_ASSET.ASSET_CODE, dbo_ASSET.RUNNING_DISTANCE, "" AS Bank, dbo_COMPONENT_TYPE.COMPONENT_TYPE_DESC, dbo_CONDITION.RATING, dbo_ASSET.OWNERSHIP, dbo_ASSET.NUMBER_ON_PLAN
INTO tblTempRS FROM ((dbo_CONDITION INNER JOIN (((dbo_ASSET INNER JOIN dbo_ASSET_ASSET_GROUP ON dbo_ASSET.ASSET_ID=dbo_ASSET_ASSET_GROUP.ASSET_ID) INNER JOIN dbo_ASSET_GROUP ON dbo_ASSET_ASSET_GROUP.ASSET_GROUP_ID=dbo_ASSET_GROUP.ASSET_GROUP_ID) INNER JOIN dbo_ASSET_COMPONENT ON dbo_ASSET.ASSET_ID=dbo_ASSET_COMPONENT.ASSET_ID) ON (dbo_CONDITION.ASSET_COMPONENT_ID=dbo_ASSET_COMPONENT.ASSET_COMPONENT_ID) AND (dbo_CONDITION.ASSET_ID=dbo_ASSET_COMPONENT.ASSET_ID)) INNER JOIN dbo_ASSET_TYPE ON dbo_ASSET.ASSET_TYPE_CODE=dbo_ASSET_TYPE.ASSET_TYPE_CODE) INNER JOIN dbo_COMPONENT_TYPE ON dbo_ASSET_COMPONENT.COMPONENT_TYPE_CODE=dbo_COMPONENT_TYPE.COMPONENT_TYPE_CODE
WHERE (((dbo_ASSET.ASSET_NAME)=Forms!frmAssetLifeMain!cboChannel) And ((dbo_ASSET.ASSET_TYPE_CODE)="ST" Or (dbo_ASSET.ASSET_TYPE_CODE)="CH") And ((dbo_ASSET_GROUP.SHORT_NAME)="MID Irrigation"))
ORDER BY dbo_ASSET.ASSET_NAME, dbo_ASSET.RUNNING_DISTANCE;
I have a querydef with one input parameter.
Set myDb = CurrentDb()
Set rs = Nothing
Set qdf = myDb.QueryDefs("qryAssetDetails_lessBank")
qdf.Parameters(0) = Me.cboChannel
strName = "tblTempRS"
strIn = qdf.SQL
strOut = Replace(strIn, "From", "INTO " & strName & " FROM")
Debug.Print strOut
qdf.Execute strOut
The execute gives a 'data type conversion error' (3421). The SQL executes OK in Access query window.
Any ideas?
SQL:
SELECT dbo_ASSET.ASSET_ID, dbo_ASSET_COMPONENT.ASSET_COMPONENT_ID, dbo_ASSET.ASSET_CODE, dbo_ASSET.RUNNING_DISTANCE, "" AS Bank, dbo_COMPONENT_TYPE.COMPONENT_TYPE_DESC, dbo_CONDITION.RATING, dbo_ASSET.OWNERSHIP, dbo_ASSET.NUMBER_ON_PLAN
INTO tblTempRS FROM ((dbo_CONDITION INNER JOIN (((dbo_ASSET INNER JOIN dbo_ASSET_ASSET_GROUP ON dbo_ASSET.ASSET_ID=dbo_ASSET_ASSET_GROUP.ASSET_ID) INNER JOIN dbo_ASSET_GROUP ON dbo_ASSET_ASSET_GROUP.ASSET_GROUP_ID=dbo_ASSET_GROUP.ASSET_GROUP_ID) INNER JOIN dbo_ASSET_COMPONENT ON dbo_ASSET.ASSET_ID=dbo_ASSET_COMPONENT.ASSET_ID) ON (dbo_CONDITION.ASSET_COMPONENT_ID=dbo_ASSET_COMPONENT.ASSET_COMPONENT_ID) AND (dbo_CONDITION.ASSET_ID=dbo_ASSET_COMPONENT.ASSET_ID)) INNER JOIN dbo_ASSET_TYPE ON dbo_ASSET.ASSET_TYPE_CODE=dbo_ASSET_TYPE.ASSET_TYPE_CODE) INNER JOIN dbo_COMPONENT_TYPE ON dbo_ASSET_COMPONENT.COMPONENT_TYPE_CODE=dbo_COMPONENT_TYPE.COMPONENT_TYPE_CODE
WHERE (((dbo_ASSET.ASSET_NAME)=Forms!frmAssetLifeMain!cboChannel) And ((dbo_ASSET.ASSET_TYPE_CODE)="ST" Or (dbo_ASSET.ASSET_TYPE_CODE)="CH") And ((dbo_ASSET_GROUP.SHORT_NAME)="MID Irrigation"))
ORDER BY dbo_ASSET.ASSET_NAME, dbo_ASSET.RUNNING_DISTANCE;SELECT dbo_ASSET.ASSET_ID, dbo_ASSET_COMPONENT.ASSET_COMPONENT_ID, dbo_ASSET.ASSET_CODE, dbo_ASSET.RUNNING_DISTANCE, "" AS Bank, dbo_COMPONENT_TYPE.COMPONENT_TYPE_DESC, dbo_CONDITION.RATING, dbo_ASSET.OWNERSHIP, dbo_ASSET.NUMBER_ON_PLAN
INTO tblTempRS FROM ((dbo_CONDITION INNER JOIN (((dbo_ASSET INNER JOIN dbo_ASSET_ASSET_GROUP ON dbo_ASSET.ASSET_ID=dbo_ASSET_ASSET_GROUP.ASSET_ID) INNER JOIN dbo_ASSET_GROUP ON dbo_ASSET_ASSET_GROUP.ASSET_GROUP_ID=dbo_ASSET_GROUP.ASSET_GROUP_ID) INNER JOIN dbo_ASSET_COMPONENT ON dbo_ASSET.ASSET_ID=dbo_ASSET_COMPONENT.ASSET_ID) ON (dbo_CONDITION.ASSET_COMPONENT_ID=dbo_ASSET_COMPONENT.ASSET_COMPONENT_ID) AND (dbo_CONDITION.ASSET_ID=dbo_ASSET_COMPONENT.ASSET_ID)) INNER JOIN dbo_ASSET_TYPE ON dbo_ASSET.ASSET_TYPE_CODE=dbo_ASSET_TYPE.ASSET_TYPE_CODE) INNER JOIN dbo_COMPONENT_TYPE ON dbo_ASSET_COMPONENT.COMPONENT_TYPE_CODE=dbo_COMPONENT_TYPE.COMPONENT_TYPE_CODE
WHERE (((dbo_ASSET.ASSET_NAME)=Forms!frmAssetLifeMain!cboChannel) And ((dbo_ASSET.ASSET_TYPE_CODE)="ST" Or (dbo_ASSET.ASSET_TYPE_CODE)="CH") And ((dbo_ASSET_GROUP.SHORT_NAME)="MID Irrigation"))
ORDER BY dbo_ASSET.ASSET_NAME, dbo_ASSET.RUNNING_DISTANCE;