Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 48
Default Refresh Excel Sheet with Access Data Frequently

Hello all, I'm attempting to refresh an Excel sheet with this code from an Access dB. Since in Excel you can't set the refresh to less then 1 minute I'm trying to do it with VBA. However the way I have it set up (below) Excel crashes after about 2 minutes. My end results would be to have Excel refresh every 10 seconds. Any and all suggestions greatly appreciated. Thank you Ron

Public Declare Function SetTimer Lib "user32" ( _
ByVal HWnd As Long, _
ByVal nIDEvent As Long, _
ByVal uElapse As Long, _
ByVal lpTimerFunc As Long) As Long

Public Declare Function KillTimer Lib "user32" ( _
ByVal HWnd As Long, _
ByVal nIDEvent As Long) As Long

Public TimerID As Long
Public TimerSeconds As Single
Sub StartAccessTimer()
TimerSeconds = 10 ' how often to "pop" the timer.
TimerID = SetTimer(0&, 0&, TimerSeconds * 1000&, AddressOf TimerProcAccess)
End Sub

Sub EndAccessTimer()
On Error Resume Next
KillTimer 0&, TimerID
End Sub

Sub TimerProcAccess(ByVal HWnd As Long, ByVal uMsg As Long, _
ByVal nIDEvent As Long, ByVal dwTimer As Long)

RefreshAccess

End Sub

'Recorded this code
Sub RefreshAccess()
With ActiveSheet.QueryTables.Add(Connection:=Array(Arra y( _
"ODBC;DSN=MS Access Database;DBQ=C:\Documents and Settings\smithr\My Documents\db1.mdb;DefaultDir=C:\Documents and Settings\smithr\My" _
), Array( _
" Documents;DriverId=25;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;")), _
Destination:=Range("A2"))
.CommandText = Array( _
"SELECT `No Customer`.ID, `No Customer`.Record, `No Customer`.`Dealer Number`, `No Customer`.`Dealer Name`, `No Customer`.Address1, `No Customer`.Address2, `No Customer`.City, `No Customer`.State, `No " _
, _
"Customer`.Zip, `No Customer`.VIN" & Chr(13) & "" & Chr(10) & "FROM `C:\Documents and Settings\smithr\My Documents\db1`.`No Customer` `No Customer`" _
)
.Name = "Query from MS Access Database"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With


End Sub
Reply
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
Error on Refresh Data Import from Access 2+2=5? Excel Discussion (Misc queries) 0 February 4th 08 04:53 PM
Data Refresh Issues when linking Access queries to Excel Rob Excel Discussion (Misc queries) 0 October 6th 06 06:40 PM
Ridirect & Refresh data from access database widman Excel Discussion (Misc queries) 2 March 11th 06 06:29 PM
Refresh data from an Excel sheet Sierras Excel Worksheet Functions 1 February 24th 06 08:44 PM
"Refresh All" won't work with external Access data located on serv Victoria @ WB Links and Linking in Excel 3 April 1st 05 08:03 AM


All times are GMT +1. The time now is 07:13 AM.

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

About Us

"It's about Microsoft Excel"