vbscript help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Panteras
    New Member
    • Aug 2007
    • 1

    #1

    vbscript help

    Hi

    I am trying to do the following using a vbscript: connect to a database using an odbc connection and return the results to an excel file. Here is the script:
    =============== =============== =
    Option Explicit

    Dim objXL,objWB,obj WS,objRange,obj QryTable

    Dim strConnection,s trFileName,strS QL,objQryT

    Set objXL = WScript.CreateO bject ("Excel.Applica tion") 'Define excel object
    Set objWB = objXL.Workbooks .Add 'Define workbook object
    Set objWS = objWB.Worksheet s("Sheet1") 'Define worksheet object
    Set objRange=objWS. Range("A1") 'Define range object
    objXL.Visible = true 'show window


    strConnection = "DRIVER={NE ON Client 32-bit (thread-safe)};UID=user ;" & _
    "PWD=password;H OST=ipaddress;S UBSYS=PT0D;DP=T ables%;MXBU=100 000;AUST=NO;CNT M=45;C" 'connection string

    strSQL = "SELECT * FROM TA1898.V_PF_507 _DELQ" 'SQL string

    Set objQryT = objWS.QueryTabl es.Add(strConne ction, objRange, strSQL) 'Define table object

    objQryT.Refresh Style = xlInsertEntireR ows 'insert rows to worksheet

    objQryT.Refresh False

    strFileName = "C:\scripts \" & "filename" & Format(Date, "yyyy-mm-dd") & Format(Time, " hh mm ss") & ".xls"

    objWB.SaveAs strFileName

    objWB.Close True
    objXL.Quit

    Set objWB = Nothing
    Set objXL = Nothing
    Set objRecordset = Nothing
    Set objConnection = Nothing


    I get an error on this line. It's a runtime error and it wont pass this part

    Set objQryT = objWS.QueryTabl es.Add(strConne ction, objRange, strSQL) 'Define table object



    I have search a lot but could not get any information on what may be wrong. Any help will be appreciated
  • VBPhilly
    New Member
    • Aug 2007
    • 95

    #2
    Maybe the provider isnt returning data?

    What is your error?

    Comment

    Working...