I have an Access database that connects to an Azure SQL Server db, and all tables are in SQL server. I'm using a free trial tier, which pauses the SQL database after an hour. If I load a form when Access opens the accdb file that shows a combo box based on querying from a small (like 10 row) table when the db is paused Access throws an error (it can take a minute or two to unpause the db).
I Googled and got some VBA code that helps, which is in a Public module. It uses an ADODB connection object to open the connection and test if the connection state is adStateOpen, and then tries a simple SELECT statement to verify it can query. If it is connected and the query worked it exits. If the connection isn't Open it waits 5 secs and tries again, up to 15 times. This works to unpause the SQL db. The function doesn't exit until it gets a connection or the number of tries is exhausted (say up to 75 secs).
Because the delay if the DB hasn't been used in an hour can be a minute or more (per Microsoft advice on unpause performance) I want to display a simple popup form with just a static Label text box that displays a "please wait" type message. That form should become visible and then the VBA code to wake the DB should run while the form sits there. Whatever event I use to invoke the wakeup function will, after the function returns, close this form and then open another form that shows some data.
I've tried putting this code in various Form events, including OnLoad, OnOpen, AfterUpdate, OnActivate. It works to trigger the wakeup, but the form doesn't become visible. I can't figure out how to (or if it's possible to) invoke and run the wakeup code with the form visible.
Here's code in the OnLoad event. UnpauseSQL is the function that wakes the db.
I Googled and got some VBA code that helps, which is in a Public module. It uses an ADODB connection object to open the connection and test if the connection state is adStateOpen, and then tries a simple SELECT statement to verify it can query. If it is connected and the query worked it exits. If the connection isn't Open it waits 5 secs and tries again, up to 15 times. This works to unpause the SQL db. The function doesn't exit until it gets a connection or the number of tries is exhausted (say up to 75 secs).
Because the delay if the DB hasn't been used in an hour can be a minute or more (per Microsoft advice on unpause performance) I want to display a simple popup form with just a static Label text box that displays a "please wait" type message. That form should become visible and then the VBA code to wake the DB should run while the form sits there. Whatever event I use to invoke the wakeup function will, after the function returns, close this form and then open another form that shows some data.
I've tried putting this code in various Form events, including OnLoad, OnOpen, AfterUpdate, OnActivate. It works to trigger the wakeup, but the form doesn't become visible. I can't figure out how to (or if it's possible to) invoke and run the wakeup code with the form visible.
Here's code in the OnLoad event. UnpauseSQL is the function that wakes the db.
Private Sub Form_Load()
Status = UnpauseSQL
If Status = True Then
DoCmd.Close acForm, Me.name, acSaveNo
DoCmd.OpenForm "Select Campus"
Else
DoCmd.Close acForm, Me.name, acSaveNo
MsgBox "Could not connect to database!"
End If
End Sub