Access is a relational database management system which provides all the tools to design and automate a database. Visual Basic for Applications or VBA is a computer programming language used to create programs in Access and other MS Office applications. Knowing how to compile a program using Microsoft Office Access can help you expand your programming skills. Write VBA code to create and compile a subroutine in Access in just a few simple steps.
- Skill level:
Other People Are Reading
Start Microsoft Office Access 2007, select "Blank Database" and click "Create." Select "Database Tools" and click "Visual Basic."
Select the "Insert" menu and click "Module."
Copy and paste the code below to your new module to create a new subroutine:
Private Sub accessQueryParameters()
Dim dB As Database
Dim rst As Recordset
Dim strSQL As String
Set dB = CurrentDb
strSQL = "CREATE TABLE tmpTable (NumField NUMBER, EmployeeName TEXT, Position TEXT);"
strSQL = "INSERT INTO tmpTable (NumField, EmployeeName, Position) "
strSQL = strSQL & "VALUES (1, 'Ana', 'Teacher');"
strSQL = "Select tmpTable.* from tmpTable;"
Set rst = db.OpenRecordset(strSQL)
Do While Not rst.EOF
Debug.Print rst.Fields("EmployeeName").Value & " is a " & _ rst.Fields("Position").Value
The subroutine will create a new table and add records to it. A query will then output the table contents to the output Window. This is an example of how you can create and compile a program using VBA. You can write and compile your own VBA code to perform a desired function.
Click the "Debug" menu and select "Compile <database name>" to compile the program. Press "F5" to run your subroutine.
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for