Applecore Pages on Microsoft Access

Creating an Access Database - Step 4: The Forms - The Track Form

This form differs slightly from the other forms in the database in that it is a sub-form, i.e. it doesn't get displayed by itself, but only within the record form.

Create a new form in design mode and set the following properties for the form:

 
Record Source qryTrack
Default View Continuous Forms
Scroll Bars Vertical Only
Record Selectors No
Navigation Buttons No
Dividing Lines No
Allow Additions No
Allow Deletions No

Now we can start adding controls to the Detail section of the form. All of the controls on this form are going to be text boxes, so the quickest way to add them all is to view the field list, and then select all of fields shown apart from TrackID and RecordID, and drag them to the form's detail section. Remove all of the labels that were created with the text boxes (Ctl-X to cut them, and then you can paste them straight into the form's header). In the order that the controls are going to appear on the form, we need to make the following changes:

TrackNumber
Name txtTrackNumber
Locked Yes
Tab Stop No
Width 0.523cm
Back Style Transparent
Special Effect Flat

TrackName
Name txtTrackName
Width 6.201cm

TrackMinutes
Name txtTrackMinutes
Input Mask 99;;"#"
Auto Tab Yes
Width 0.619cm

TrackSeconds
Name txtTrackSeconds
Input Mask 99;;"#"
Auto Tab Yes
Width 0.619cm

TrackAuthor
Name txtTrackAuthor
Width 5.381cm

TrackNotes
Name txtTrackNotes
Width 4.772cm

Now move the controls from their original placings on the form so that they are now aligned vertically about 0.1cm below the top of the Detail section, and resize the Detail so that there is a space of about 0.1cm under the text boxes. Add a label to the detail, and set the caption to ":", and place this between txtTrackMinutes and txtTrackSeconds.

Next, we shall add two text boxes to the form footer, to display the total time for the record. Call the text boxes "txtTotalMinutes" and "txtTotalSeconds". As these are both calculated controls, we need to distinguish them from other controls, so we set the following properties for them:
Locked Yes
Tab Stop No
Width 0.619cm
Back Style Transparent
Special Effect Flat

We shall set the ControlSource of txtTotalMinutes to:

=Sum([TrackMinutes])+(Sum([TrackSeconds])\60)

and that of txtTotalSeconds to:

=(Sum([TrackSeconds]) Mod 60)

Now we need to add a few bits of code to the form to update the record's total time, and to ensure that if the calculated controls get the entered, we move to another field:

 
Private Sub txtTotalMinutes_GotFocus()
    DoCmd.GoToControl "txtTrackName"
End Sub

Private Sub txtTotalSeconds_GotFocus()
    DoCmd.GoToControl "txtTrackName"
End Sub

Private Sub txtTrackNumber_GotFocus()
    DoCmd.GoToControl "txtTrackName"
End Sub

Private Sub txtTrackSeconds_AfterUpdate()
    DoCmd.RunCommand acCmdSaveRecord
    Me!txtTotalMinutes.Requery
    Me!txtTotalSeconds.Requery
End Sub

Top

 


HOME | NEW | TABLES | QUERIES | FORMS | REPORTS | GENERAL | API | DOWNLOADS | TUTORIAL | RESOURCES
E-MAIL
Copyright & Disclaimer

 

Last modified at 06/06/2006 15:01:45