Here is my code for this (it is done on Form load):
When I run my project, nothing loads for about 15 seconds and I get this error:Code:Private Sub Form_Load() Set cn = New ADODB.Connection cn.ConnectionString = "string" cn.CursorLocation = adUseClient cn.ConnectionTimeout = 30 cn.Open , , , adAsyncConnect Dim lngLoop As Long Do While cn.State = adStateConnecting Label2.Caption = "Loading... " & Choose(lngLoop Mod 4 + 1, "|", "/", "-", "\") Sleep 300 DoEvents lngLoop = lngLoop + 1 Loop End Sub Private Sub cn_ConnectComplete(ByVal pError As ADODB.Error, adStatus _ As ADODB.EventStatusEnum, ByVal pConnection As ADODB.Connection) Set rs = New ADODB.Recordset rs.Open "SELECT * FROM `mydb`ORDER BY `effective_date` DESC", cn, adOpenDynamic, adLockOptimistic Label2.Caption = rs.Fields("number") rs.Close cn.Close End Sub
Run-time error '3709':
The connection cannot be used to perform this operation. It is either closed or invalid in this context.
...after I select debug the line "rs.open...." is highlighted.
I intentionally removed my IP from the whitelist in order to build my connections around this. I was suprised to see that my form did not load right away with the adAsyncConnect
What am I doing wrong? Thanks.
I want the form to load right away, have label 2 say "loading" as the connection is established. Once connection is established call loaddataincontrols. If the connection times out then do nothing.




Reply With Quote