bLySs (This in XL2003, don't know if this will effect anything)...
Maybe you can extract the relevant from the code below, which I set up this
morning. It queries an access database on my hard drive called test.mdb,
takes two fields from a table called tblCatalogueHeader and sets up a
parameter of CatCode. It then adds a parameter called CatCode and sets the
parameter to prompt the user xlPrompt with the text shown. (It can also be
set with a fixed string or call the value from another cell. (I have
deliberately left all the methods out of the querytable setup as it is for
this example unnecessary code, but if you want the query to background
refresh, overwrite cells, etc, these will need to be set). I actually
learned something myself with this today, thanks!
Sub SetParameters()
Dim qry As QueryTable
Dim prm As Parameter
With ActiveSheet.QueryTables.Add(Connection:="ODBC;DSN=MS Access
Database;DBQ=C:\Test.mdb;DefaultDir=C:;DriverId=25;FIL=MS
Access;MaxBufferSize=2048;PageTimeout=5;" _
, Destination:=Range("A1"))
.CommandText = Array( _
"SELECT tblCatalogueHeader.CatCode, tblCatalogueHeader.AmountInv" &
Chr(13) & "" & Chr(10) & _
"FROM `C:\Test`.tblCatalogueHeader tblCatalogueHeader" & Chr(13) &
"" & Chr(10) & _
"WHERE (Catcode=?)")
.Name = "test"
End With
Set qry = ActiveSheet.QueryTables(1)
Set prm = qry.Parameters.Add("CatCode", xlParamTypeVarChar)
qry.Parameters(1).SetParam xlPrompt, "Enter a Catalogue Code (e.g 00000101)"
qry.Refresh
End Sub
--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
[email protected]