Is there a quick, down and dirty routine for automatically updating a VBA form with SQL data, either whenever there has been a change in the SQL file, or perhaps on a periodic basis (every 5 to 30 minutes).
Here is one method. While the code below writes to a Worksheet you can just as easily change it to update data on a UserForm. The Function MyTimer will fire every 10 seconds and then update the SQL. One nice thing about the OnTime function is that you can continue to work on the Workbook while it waits to fire.
Dim dbTest As Database
Dim rsTest As Recordset
Sub Button1_Click()
Set dbTest = OpenDatabase("C:\Development\html\Test.mdb"
Set rsTest = dbTest.OpenRecordset("Select * From Books"
MyTimer
End Sub
Function MyTimer()
Dim R As Integer
Dim C As Integer
Dim rsData As String
rsTest.Requery
R = 0
Sheets("Sheet1".Cells(1, 1).Value = "Last Update At: " & Now()
Do While rsTest.EOF <> True
For C = 0 To rsTest.Fields.Count - 1
rsData = rsTest.Fields(C).Value
Sheets("Sheet1".Cells(R + 2, C + 1).Value = rsData
Next C
R = R + 1
rsTest.MoveNext
Loop
Application.OnTime Now + TimeValue("00:00:10", "MyTimer"
End Function
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.