Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Querytables parameters

I am trying to use the parameters feature of query tables and keep getting a
type mismatch. Below is code:

Dim param1 As QueryTable.Paramters
Dim param2 As QueryTable.Parameters
Dim qt As QueryTable

Set qt = Sheets("sheet1").QueryTables(1)
qt.Sql = "select wodate from natop.dbo.workmast where (wodate between ?
and ?)"
Set param1 = qt.Parameters.Add("Start Parameter", xlParamTypeVarChar)
param1.SetParam xlConstant, "01/01/2005"
Set param2 = qt.Parameters.Add("End Parameter", xlParamTypeVarChar)
param2.SetParam xlConstant, "04/01/2005"
qt.Refresh

The mismatch is coming on my first dim statement. What am I doing wrong?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default Querytables parameters

Perhaps because you have misspelled Parameters?

--

Vasant

"Dwaine Horton" wrote in message
...
I am trying to use the parameters feature of query tables and keep getting

a
type mismatch. Below is code:

Dim param1 As QueryTable.Paramters
Dim param2 As QueryTable.Parameters
Dim qt As QueryTable

Set qt = Sheets("sheet1").QueryTables(1)
qt.Sql = "select wodate from natop.dbo.workmast where (wodate between

?
and ?)"
Set param1 = qt.Parameters.Add("Start Parameter", xlParamTypeVarChar)
param1.SetParam xlConstant, "01/01/2005"
Set param2 = qt.Parameters.Add("End Parameter", xlParamTypeVarChar)
param2.SetParam xlConstant, "04/01/2005"
qt.Refresh

The mismatch is coming on my first dim statement. What am I doing wrong?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 595
Default Querytables parameters

Dwaine

Dim param1 as Parameter

When you use a dot operator in a Dim statement, you're saying
ObjectLibrary.Object. In this case, you're saying that QueryTable is an
object library and it's not. Both the QueryTable object and the Parameter
object are objects in the Excel object library. You could say this

Dim param1 As Excel.Parameter

but it's totally unnecessary.

Also, you'll want those variable to be dimmed as Parameter not Parameters.
Parameters, the plural, is a collection object that can contain multiple
Parameter objects. For what you're doing, you just want the singular
Parameter.

Finally, fix the mispelling like Vasant said.


--
Dick Kusleika
Excel MVP
Daily Dose of Excel
www.dicks-blog.com

Dwaine Horton wrote:
I am trying to use the parameters feature of query tables and keep
getting a type mismatch. Below is code:

Dim param1 As QueryTable.Paramters
Dim param2 As QueryTable.Parameters
Dim qt As QueryTable

Set qt = Sheets("sheet1").QueryTables(1)
qt.Sql = "select wodate from natop.dbo.workmast where (wodate
between ? and ?)"
Set param1 = qt.Parameters.Add("Start Parameter",
xlParamTypeVarChar) param1.SetParam xlConstant, "01/01/2005"
Set param2 = qt.Parameters.Add("End Parameter", xlParamTypeVarChar)
param2.SetParam xlConstant, "04/01/2005"
qt.Refresh

The mismatch is coming on my first dim statement. What am I doing
wrong?



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 593
Default Querytables parameters


Dick Kusleika wrote:
Both the QueryTable object and the Parameter
object are objects in the Excel object library. You could say this

Dim param1 As Excel.Parameter

but it's totally unnecessary.


'Optional' could be a better way of putting it <g.

By omitting the library name you are making an assumption, in this case
that a reference to Excel has been set and that it has a higher
precedence than any other referenced library with a Parameter class
e.g. ADODB. I wager that, in contrast, for variables of type
ADODB.Recordset you *always* include the library name, yet how often do
you reference another library with a Recordset class? Convention has a
lot to answer for.

I often use Excel.<class in code for which I think it may get some
future re-use in a non-Excel project.

Jamie.

--

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 595
Default Querytables parameters


"Jamie Collins" wrote in message
oups.com...

Dick Kusleika wrote:
Both the QueryTable object and the Parameter
object are objects in the Excel object library. You could say this

Dim param1 As Excel.Parameter

but it's totally unnecessary.


'Optional' could be a better way of putting it <g.


No doubt. I've always assumed that Excel had a higher precedence than
anything else, but I probably shouldn't.

By omitting the library name you are making an assumption, in this case
that a reference to Excel has been set and that it has a higher
precedence than any other referenced library with a Parameter class
e.g. ADODB. I wager that, in contrast, for variables of type
ADODB.Recordset you *always* include the library name, yet how often do
you reference another library with a Recordset class? Convention has a
lot to answer for.


You'd win that wager. I never thought about it, but I'll bet I reference
other libraries with Recordset and have just gotten lucky in the order.


I often use Excel.<class in code for which I think it may get some
future re-use in a non-Excel project.


That's one I've never considered. My apps would be a heck of a lot harder
to port to, say, VB6.

--
Dick Kusleika
MVP Excel
Daily Dose of Excel
http://www.dicks-blog.com




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 595
Default Querytables parameters


You'd win that wager. I never thought about it, but I'll bet I
reference other libraries with Recordset and have just gotten lucky
in the order.


I don't know why I would bet that. It's probably not true. I don't know
what libraries have Recordset, but I do know that I've never had both ADO
and DAO referenced in the same project. I still won't be changing my habit
though :)


--
Dick Kusleika
Excel MVP
Daily Dose of Excel
www.dicks-blog.com


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
QueryTables Add Marta[_3_] Excel Programming 0 January 19th 05 05:32 PM
Error when trying to use QueryTables.Add Mindblower Excel Programming 0 August 31st 04 01:44 PM
With ActiveSheet.QueryTables.Add [email protected] Excel Programming 4 January 6th 04 04:58 PM
QueryTables Interrupt if URL is Down Steve Hieb Excel Programming 0 November 17th 03 10:07 PM


All times are GMT +1. The time now is 04:35 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"