This is a simple database that contains “tblStaffers” containing names of the office staffers, “tblProjects” containing names of the office projects, and “tblStatusReports” containing the “StafferID” (link to Staffer table), the “ProjectID” (link to Projects table), a “Date” field, and a “Notes” field.
There is a main form, “frmStaffEntry,” with a subform, “frmStatusReports,” for a user to add/delete/modify status reports for the projects the staffers are working on.
“frmStaffEntry” contains unbound Combo Box “ChooseStaff” where the user chooses the name of the staffer (from “tblStaffers”) whose entries are then shown in “frmStatusReports”
The user can choose how to sort/show the status report entries via an Option Group on “frmStatusReports” named “SortOption” with Default Value = 1. “SortOption” contains 2 Option Buttons: “DateOption” has value set to 1; “ProjectOption” has value set to 2.
The default sort is “qrySRSortDate” - which sorts tblStatusReports by reverse Date order (first) then by alphabetical Project order (second). (The Record Source for “frmStatusReports” is “qrySRSortDate”)
The other sort choice is “qrySRSortProject” which sorts tblStatusReports by alphabetical Project order (first) then by reverse Date order (second).
“frmStaffEntry” VBA routines are:
Expand|Select|Wrap|Line Numbers
- Private Sub ChooseStaff_AfterUpdate()
- ‘Find record for chosen staffer
- Dim rs As Recordset
- Set rs=Me.RecordsetClone
- rs.FindFirst “[StafferID] = “ & Str(Nz(Me![ChooseStaff],0))
- If Not rs.EOF Then Me.Bookmark = rs.Bookmark
- rs.Close
- Set rs = Nothing
- End Sub
- Private Sub ChooseStaff_Enter()
- ‘Update subform based on chosen staffer
- Me![ChooseStaff].Requery
- Forms!frmStaffEntry.Form!frmStatusReports.Requery
- End Sub
Expand|Select|Wrap|Line Numbers
- Private Sub Form_AfterUpdate()
- ‘ Requery status reports after an entry has been made or modified.
- ‘ Requery uses whichever SortOption is in effect
- Me.Requery
- End Sub
- Private Sub SortOption_AfterUpdate()
- ‘ Show status reports based on sort choice made by user
- Select Case SortOption.Value
- Case 1
- Me.RecordSource = “qrySRSortDate”
- Case 2
- Me.RecordSource = “qrySRSortProject”
- End Select
- End Sub
I thought the “frmStaffEntry” subroutine: ChooseStaff_Enter() shown above would take care of the problem, since the subform record source is “qrySRSortDate” and the “SortOption” default value is set to one.
I've researched on the web but can't find example which uses an Option Group like I have. I’ve tried various other things, such as making RecordSource = “qrySRSortDate” in the ChooseStaff_Enter() subroutine, but have gotten weird results. My gut feel is that what I’ve got is almost right but I can’t figure out that little gotcha I’ve overlooked.
Any help would be appreciated. Thanks
Janice