VBA to close all Connections/Recordset opened.

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
Hi, is there a way for a VBA to close all connections/Recordset opened.
I am wanting this because i do not want any user to lock the database maybe/due to any error etc. and prevent other users from access the main database.


Thanks in advance.
Pedie
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Pedie

You can just close a recordset like this:
Code:
rst.Close
and a connection like this:
Code:
conn.Close
You should do this as soon as you've finished with the recordset/connection.
 
Upvote 0
Norie, thanks for quick reply.
I do that...I mean like the way you said.
I also include error trap in every code. But sometime when error happens it happends to lock my Main database and wont let me add any new records to it. Why does this happen?
 
Upvote 0
Pedie

Because you are using error traps, or more likely because you haven't quite set them up properly.:)
 
Upvote 0

Because you are using error traps, or more likely because you haven't quite set them up properly.:)


Yep...maybe somewhere...
In a laymans term, pls let me know the Recordset types and cursor types; Do i always needs to specify the type of cursor? Recordset types?

what will happen if i use something like this;
Code:
[/FONT]
[LEFT][FONT=Courier New]rst.CursorLocation = adUseClient
rst.CursorType = adOpenStatic
rst.LockType = adLockBatchOptimistic[/FONT]
[FONT=Courier New][/FONT] 
[FONT=Courier New]or [/FONT]
[FONT=Courier New][/FONT] 
[FONT=Courier New]CursorType:=adOpenKeyset
CursorType:=adOpenStatic[/FONT]
[FONT=Courier New]etc[/FONT]
[FONT=Courier New][/FONT] 
[FONT=Courier New]
Does this lock the recordset/table till the current user is completely done with the adding/deleting/editing etc?
Does this

Thanks again in advance.[/LEFT]
 
Upvote 0
Pedie

Not sure what this has to do with closing recordsets and connections.
 
Upvote 0

Not sure what this has to do with closing recordsets and connections.



Like i said earlier Norie,
HTML:
I am wanting this because i do not want any user to lock the database maybe/due to any error etc. and prevent other users from access the main database.
I thought maybe if i use the right type if cursor/recordset it won't prevent others from accessing the recordset and performing activity on it..[I could be wrong .... just a thought.].
Beside that I also want to know what Cursors mean in access....


Thanks again.
 
Upvote 0
Pedie

I can't really help with cursors, especially since I've no idea whether it's ADO or DAO you are using, or what you are trying to do.

One thing you really need to consider is not using code, then you wouldn't need to worry about this sort of thing.:)
 
Upvote 0
Thanks again Norie though...
In my future projects, 'll try to minimize the use of codes:biggrin:.

Pedie
 
Upvote 0
Pedie

Why not try it with the current project?
 
Upvote 0

Forum statistics

Threads
1,224,507
Messages
6,179,181
Members
452,893
Latest member
denay

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