LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default External Data Via VBA was working - now not so much

Hi

I have been attempting to get the following to work, and thought I had
sussed it, however it suddenly has started generating a "1004 General
ODBC Error".

There have been no changes since the last successful trial, so I am a
bit mystified.

Any Help/Advice would be gratefully received

Sub Import()
Dim strConnParam As String
Dim strSql As String
Dim strDbname As String
Dim strPath As String
Dim strName As String
Dim dtFromDate As Date
Dim dtToDate As Date
Dim rngUbr As Range
Dim ws As Worksheet
Dim strUbr As String

DeleteAllQueries
DeleteNames
Set ws = Worksheets("Sheet1")
Set rngUbr = ws.Range("A1")
strUbr = rngUbr
dtFromDate = Format(rngUbr.Offset(0, 1).Value, "mm/dd/yyyy")
dtToDate = Format(rngUbr.Offset(0, 2).Value, "mm/dd/yyyy")
strPath = "J:\Gary\History\"
strName = "j:\gary\history\History.mdb"
strConnParam = "ODBC;DSN=MS Access Database;" & _
"DBQ=" & strName & ";" & _
"DefaultDir=" & strPath & ";" & _
"Driverid=25;" & _
"FIL=MS Access;" & _
"MaxBufferSize=2048;" & _
"PageTimeout=5;" & _
"Destination:=Range(""A4""))"
strSql = "SELECT Data.Ubr," & _
"Data.Date," & _
"Data.BW," & _
"Data.`10 SACM`," & _
"Data.`512 SACM`," & _
"Data.`3 SACM`," & _
"Data.`2 SACM`," & _
"Data.`1 SACM`," & _
"Data.`150 SACM`," & _
"Data.`1500 SACM`," & _
"Data.`750 SACM`," & _
"Data.`300 SACM`," & _
"Data.`600 SACM`" & _
"FROM history.data " & _
"WHERE Data.Ubr='" & strUbr & "' AND " & _
"Data.Date=#" & dtFromDate & "# AND " & _
"Data.Date<=#" & dtToDate & "#"


With ActiveSheet.QueryTables.Add(Connection:=strConnPar am, _
Destination:=Range("A4"))
.CommandText = strSql
.PreserveFormatting = True
.AdjustColumnWidth = False
.RefreshStyle = xlInsertDeleteCells
.RefreshStyle = xlOverwriteCells
.Refresh BackgroundQuery:=False
End With
End Sub


Many Thanks

Gary Majdanek

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
External Data Warning Message - I have No External Data in wrkbk Cass_makeitfun[_2_] Excel Discussion (Misc queries) 0 May 12th 10 09:02 PM
Getting External Data based on criteria insde of the external data BigMacExcel Excel Discussion (Misc queries) 0 August 31st 09 06:41 PM
External Data Refresh not working Mike B in VT Excel Discussion (Misc queries) 0 February 10th 06 06:23 PM
External References not working right. Dread_Pirate_Roberts Excel Worksheet Functions 13 December 8th 04 11:07 PM
Get external data not working properly Kanti Excel Programming 4 November 6th 03 06:36 AM


All times are GMT +1. The time now is 08:27 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"