Wait until ADODB connection execute

Ombir

Active Member
Joined
Oct 1, 2015
Messages
433
Hi Friends,


I'm using below code to get count of records in access table which has been updated through sql server through ADODB connection (lcnn).

Code:
    SQL1 = "INSERT INTO [Users] " & _
    "Select DISTINCT USER_ID " & _
    "FROM " & _
    "[ODBC;Driver=SQL Server; " & "SERVER=Destiny\SQLEXPRESS;DATABASE=Sample;" & "UID=sam;PWD=password;]." & _ "[User_login] "
    lcnn.Execute SQL1
    
    Sleep 5000
    
    usercnt = DCount("*", "users")
    
    If usercnt >= 20 Then
       'Do something
    End If

The problem I'm facing is usercnt isn't get updated without delay of 5 secs. Code works fine in debug mode without using Sleep Api.

Can somebody help me with faster alternative (preferably without using recordset object) by which I can avoid 5 secs delay ??
 
I Haven't seen the construction/syntax you are using where you create a connection but also put connection information into the SQL string as well. I don't believe it's necessary to wait 4-5 seconds for DCount() but I'm still not sure how many databases you are using, since you seem to have two connection strings in use, plus the database that you are running this from (?) so that could be 3 databases, possibly - extractor.mdb, the sample database on server destiny, and the one that you are running your code from (if its not extractor.mdb).

You missed the simplest option, in my opinion:
select count(*) from Users

Note that if you are connecting to a remote server, you will have to wait some amount of time.
 
Last edited:
Upvote 0

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Re: #2 - there's no .Recordsaffected property for a Select statement. Now I have no idea what it is you want; only what you don't want.
 
Upvote 0

Forum statistics

Threads
1,221,704
Messages
6,161,390
Members
451,701
Latest member
ckrings

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top