Hi, I have a problem that has been addressed here before, but I can't seem to make the answer work. I am populating an Excel spreadsheet from MS Access with the following code. It runs correctly the first time, then the second time, it gives the rt error 1004, Method 'Range' of object '_Global' failed. I know I need to fully qualify the range, but I'm having a hard time accomplishing that. Here is my code. Can anybody give me some advice? Thanks for any help you can give.
Code:
Dim appExcel As Excel.Application
Dim wbook As Excel.Workbook
Dim wsheet As Excel.Worksheet
Set appExcel = CreateObject("Excel.Application")
Set wbook = appExcel.Workbooks.Open("C:\Brenda\Daily1.xls", UpdateLinks:=1, Password:="password")
Set wsheet = wbook.Sheets("Sheet1")
appExcel.Visible = True
appExcel.UserControl = True
With ActiveSheet.QueryTables.Add(Connection:= _
"OLEDB;Provider=MSDAORA.1;User ID=odsl48_readonly;Password=readmeprod; Data Source=ODSL48P1", _
Destination:=Range("A1"))
.CommandType = xlCmdSql
.CommandText = Array( _
"select /*+ first_rows */ (CASE WHEN meter_num in ('28187001', '28187002', 'BRPIN01055', 'BRPIN01065') THEN 'PINNACLE' WHEN meter_num in ('28112001', '28112002', 'BRETCMTR7513', 'BRETCMTR7514') THEN 'FR" _
, _
"ANKLIN'
Comment