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
Bookmarks