MS Access 2007 Step By Step - Asim Abbasi
CH1: Overview | CH2: MS Access Local & Linked Tables | CH3: MS Access Queries | CH4: MS Access Reports & Forms | CH5: MS Access Modules & Macros | CH6: MS Access Data Import/Export Feature | CH7: MS Access Built-In Functions
Chapter 5: MS Access Modules & Macros
auto_login Visual Basic Code

Figure 5-4: auto_login module code.
________________________________________
The auto_login code is nothing but a single function named AutoExec().
The function begins with the keyword ‘Function’ and ends with ‘End
Function’ as shown in Figure 5-4 as well as below.
![]()
.
.
.
![]()
If any module contains the AutoExec function, it will be the first thing
that will get executed within the module upon execution.
To use variables and objects in code, you first have to define them.
That’s the reason we have defined ‘db’ as an object variable and
‘strConnect’ as String variable at the beginning of function code.
![]()
In case if the error happens while the execution of the code, we want to have the message to be popped up to the user. To do this we have written an error capturing code as shown below.

Figure 5-5: Error capturing routing.
________________________________________
If the error occurs while the execution of the code, the microprocessor
will jump to AutoExec_Err subroutine. In this subroutine we have a
command of ‘MsgBox’ which is used to pop up message box. After the user
will click <OK> on the popped up message box, the code execution will
end as we have ‘Resume AutoExec_Exit’ command in the next line. When the
microprocessor encounters this command, it jumps to the ‘AutoExec_Exit’
subroutine. Underneath this subroutine we have the command of ‘Exit
Function’ which results in termination of the code execution.
If you are new to Visual Basic then there is no need to mess with this
code. All you need to do is to change the Username and Password section
of the code as supplied by Oracle Database Administrator and the DSN you
created earlier in this book i.e. ‘ODBC Link to Oracle Server’. As shown
in the code line below the username is ‘system and password is ‘takveendb’.
strConnect = "DSN=ODBC Link to Oracle Server; SERVER=;UID=system; PWD=takveendb"
In the whole code you just have to replace the word ‘system’ with the
username you have to login to Oracle Database Server and ‘takveendb’
with the password for the same account. Once done, then upon the
execution of the module MS Access will use this account (login/password)
to do the data manipulation as per your command, inside Oracle tables,
provided the Oracle user account has sufficient privileges.
Chapter 5: MS Access Modules & Macros
CH1: Overview | CH2: MS Access Local & Linked Tables | CH3: MS Access Queries | CH4: MS Access Reports & Forms | CH5: MS Access Modules & Macros | CH6: MS Access Data Import/Export Feature | CH7: MS Access Built-In Functions
Share with others: