Results 1 to 10 of 10

Queries in code

Threaded View

  1. #1
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Manchester England
    MS-Off Ver
    Excel 2010
    Posts
    992

    Queries in code

    I am trying to write a query in VBA but have fallen at the last fence

    Sub writeQuery()
    Dim Dest as Range
    Dim FROM as Date
    FROM = CDate(#01/01/2012#)
    ShName = "GUMCURR"
    Set Dest = Sheets(shName).Range("A10")
    SetQueries ShName,Dest,FROM
    End Sub
    --------------------------------------------
    Sub SetQueries(shName,Dest,FROM)
        Const SAGECONN1 As String = "ODBC;DSN = SAGE LINE 100;UID= test;;"
        Dim qtSage As QueryTable
        Dim SQLstr As String
                      SQLstr = SQLGUMCURR(FROM)
                      Set rngDest = Dest
                      Set qtSage = Worksheets(ShName).QueryTables.Add(SAGECONN1, rngDest, strSQL)
               qtSage.RefreshStyle = xlOverwriteCells
             
            
            *  Sheets(ShName).Range("A10").Select
           *   Selection.ListObject.QueryTable.Refresh BackgroundQuery:=False
    End Sub
    ------------------------------
    Function  SQLGUMCURR(FROM)
    ----
    ----
    ----
    End Function
    This falls down at the last two lines marked with* where I get "Method Range of Object_Global failed". I have tried avoiding the Select and using the variable Dest but to no avail
    Can anyone see where I have gone wrong. I have not given the details of the SQLstr, but could it be there ? Or is it to do with using Select
    Last edited by j_Southern; 03-23-2012 at 12:35 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1