What is the basic format of a Access VBA module

A

azhu.uwaterloo

Hello,
I am almost completely new to Access VBA so pardon me if this question
is asked before.
Anyway, I came across somewhere that I have read before that before I
exit an Access VBA module, I am supposed to clear the database or do
something to free the database is it? May I know how it is done and
why should I be doing that?

Thanks!
 
A

Albert D. Kallal

Hello,
I am almost completely new to Access VBA so pardon me if this question
is asked before.
Anyway, I came across somewhere that I have read before that before I
exit an Access VBA module, I am supposed to clear the database or do
something to free the database is it? May I know how it is done and
why should I be doing that?

Hum, I don't know exactly what you are asking about.

When in the code editor, is a really good idea to do a

debug->compile

that way, any syntax errors are found (and, hopefully you have the option
explicit turned on). Right after you done a debug-compile, you can click on
the "x" (or ctrl-f4) to close that code window, and the then hit ctrl-s
(saving accomplishes two handy things:

1) it ensures you saved you work
2) if you save right after you compile and close, then when you
re-open the code editor, that code will not be opened next time (and, if you
working on code..then do a compile, save..and skip the closing step..and you
code will stay open next time you return -- so, depending on what you doing,
and if you done working on the particular piece of code..the close step is
your choice.

During the day if you doing any amount of development, you also need to do a
compact and repair, as any form etc you edited is actually copied over and
over..and the database will bloat very rapid...so, frequently doing a
compact and repair is a great job...
 
L

Larry Linson

I think it is possible that you are referring to the case where, in your VBA
code, you Dim database and recordset objects, open the recordset, use
(retrieve/update) the information in the recordset... that, then before
exiting the procedure, you should Close any object that you Opened, and, for
safety's sake, set any object you Dim'd to the value Nothing. Ex.,

Function yourfunctionname () As somedatatype

Dim db as DAO.Database
Dim rs as DAO.Recordset

Set db = CurrentDB
Set rs = db.OpenRecordset("sometableorqueryname")

. . . <this is where you work with the recordset>

rs.Close
Set rs = Nothing
Set db = Nothing
Exit Function

End Function

Larry Linson
Microsoft Access MVP
 
Top