We help IT Professionals succeed at work.
Get Started

VBA Select Statement and/or

cebu1014
cebu1014 asked
on
337 Views
Last Modified: 2012-07-29
I am trying to modify this query that was created by another to run in VBA. I get error 13 type mismatch . What I want to do is add a filter to include >000000050000000 and < 000000500099999 to what is listed already. The overflow line in select statement is causing me problems as well.


With ActiveSheet.QueryTables.Add(Connection:=Array(Array( _
        "ODBC;DSN=tap;ServerName=SHCPSERVER.1583;ServerDSN=TAP;ArrayFetchOn=1;ArrayBufferSize=8;TransportHint=TCP;DecimalSymbol=.;ClientVersion" _
        ), Array("=8.60.192.030;CodePageConvert=1252;AutoDoubleQuote=0;")), Destination _
        :=Range("A1"))
        .CommandText = Array( _
       "SELECT ITEM.NBR, ITEM.DESCR, ITEM.USR_DEF_4, ITEM.PRIME_VEND, ITEM.CAT, ITEM.SUB_CAT, ITEM.PRC_1_1, ITEM.PRC_2_1, ITEM.AVG_COST, ITEM.STD_COST, ITEM.USR_DEF_1, ITEM.USR_DEF_3, ITEM.USR_FMT_NUM_2  FROM ITEM ITEM  WHERE (ITEM.NBR<'000000000999999'" _
        , ")  ORDER BY ITEM.NBR")

        .Name = "ITEMIMAS"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .PreserveColumnInfo = True
        .SourceConnectionFile = _
        "C:\Documents and Settings\kip.TAP\Application Data\Microsoft\Queries\ITEMIMAS.dqy"
        .Refresh BackgroundQuery:=False
    End With
Comment
Watch Question
Cost Accountant
CERTIFIED EXPERT
Top Expert 2012
Commented:
This problem has been solved!
Unlock 1 Answer and 1 Comment.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE