View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
FSt1 FSt1 is offline
external usenet poster
 
Posts: 3,942
Default Get External Data

hi
adding a new query and refreshing an existing query are two different things.
the code you posted is for created a new query each time it's run.
you only need to do that once. after that all you need to do is refresh.
a sub like this is what i use and is all that is needed to refresh.
Private Sub CommandButton1_Click()
Range("A1").Select
Range("A1").QueryTable.Refresh BackgroundQuery = False
MsgBox "refresh complete"
End Sub

you say you ran this code for a year???? i don't see how you didn't get this
message a year ago unless you are creating a new query in a new file each
time.
if your are creating a new query each time, remove all lines in the code
that refer to "refresh". creating and refreshing in the same sub is double
duty and redundent and may be the source of your error.

Regards
FSt1

"Chuck" wrote:

Office 97 Pro
Excel file written 2005 and run daily for about a year.
The Excel file gets external data from an Access data base.
Tried to run the Excel file today.
Error message: [Microsoft][ODBC Microsoft Access Driver] Invalid procedure
call.

Macro in Excel file:

Sub GetMDBdata()
'
' GetMDBdata Macro
' Macro recorded 2/2/2005 by Chuck
'
' Keyboard Shortcut: Ctrl+o
'
With ActiveSheet.QueryTables.Add(Connection:= _
"FINDER;C:\Program Files\Microsoft Office\Queries\Get Data from
mdb.dqy", _
Destination:=Range("A1"))
.FieldNames = True
.RefreshStyle = xlInsertDeleteCells
.RowNumbers = False
.FillAdjacentFormulas = False
.RefreshOnFileOpen = False
.HasAutoFormat = True
.BackgroundQuery = True
.TablesOnlyFromHTML = True
.Refresh BackgroundQuery:=False
{ *** The line above is where the sub hangs.}
.SavePassword = True
.SaveData = True
End With
End Sub

I made a new blank Excel file and established a new get external query.
Same error message as before.

Examined the original Get Data from mdb.dqy file and the new Get Data2 from
mdb.dqy. They were identical.

Re-installed Office97. Did not help

If it makes any difference - I had Office 2000 pro installed (in a different
directory from Office97 so I could run either program) for some time. Didn't
like Access 2000 so I removed all of Office 2000. Cleaned up registry and
directories.

I'll be very greatful for any suggestion for getting any Access data into any
Excel file.