Some Introductory Programming
1. Structured Query Language (SQL)
- used for queries.
- a standard database product.
2. Visual Basic for Applications
- use of Visual Basic to develop an Access application.
The Access Design Screen version of a Query
Show all students with an overall mark less than 40%
The Access SQL version of the query
Run the Query
Example of Visual Basic programming.Calculate outcome, put in field on record.
A table contains student number, name, coursework mark, exam mark and an empty field for the result (pass or referred).
Module Total = 75% coursework + 25% exam which is shown in a calculated field on the form.
Result : 40% or over = Pass, otherwise Referred.
Exam Mark – Properties
OnExit – Code Builder
Enter code as below.
Note “Text 10” = module total as calculated on form.
Text 10 Properties.
Enabled = No (To disallow entry – module total is always calculated by computer).
Run the Form (Enter data)
Let’s add an Exit button
Add a Command Button, call it Exit
Use Wizard to specify Close Form action.
Sub Exit_button_Click ()On Error GoTo Err_Exit_button_Click
DoCmd Quit
Exit_Exit_button_Click: Exit Sub
Err_Exit_button_Click: MsgBox Error$ Resume Exit_Exit_button_Click
End Sub
The Wizard will insert the following code as an OnClick event procedure:
Sub Exit_button_Click ()On Error GoTo Err_Exit_button_Click
continue = MsgBox("Do you really want to quit?", 4)
If continue = 6 Then DoCmd Quit End If
Exit_Exit_button_Click: Exit Sub
Err_Exit_button_Click: MsgBox Error$ Resume Exit_Exit_button_Click
End Sub
Add three extra lines to give the following:
New lines
Access now asks for confirmation before closing the form.