I am using Access 2003 on Windows XP.
This is a simple database that contains “tblStaffers” containing names of the office staffers, “tblProjects” containing names of the office projects, and “tblStatusRepor ts” 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, “frmStatusRepor ts,” 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 “frmStatusRepor ts”
The user can choose how to sort/show the status report entries via an Option Group on “frmStatusRepor ts” 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 tblStatusReport s by reverse Date order (first) then by alphabetical Project order (second). (The Record Source for “frmStatusRepor ts” is “qrySRSortDate” )
The other sort choice is “qrySRSortProje ct” which sorts tblStatusReport s by alphabetical Project order (first) then by reverse Date order (second).
“frmStaffEntry” VBA routines are:
“frmStatusRepor ts” VBA routines are:
This all works great – the user can choose a staffer and switch between the sorts to their hearts content. My problem comes when the user has left the sort on “ProjectOption” then moves to the main form (“frmStaffEntry ”) and chooses another staffer. The sub form (“frmStatusRepo rts”) refreshes but does not revert to the default “DateOption” (“qrySRSortDate ”).
I thought the “frmStaffEntry” subroutine: ChooseStaff_Ent er() 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_Ent er() 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
This is a simple database that contains “tblStaffers” containing names of the office staffers, “tblProjects” containing names of the office projects, and “tblStatusRepor ts” 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, “frmStatusRepor ts,” 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 “frmStatusRepor ts”
The user can choose how to sort/show the status report entries via an Option Group on “frmStatusRepor ts” 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 tblStatusReport s by reverse Date order (first) then by alphabetical Project order (second). (The Record Source for “frmStatusRepor ts” is “qrySRSortDate” )
The other sort choice is “qrySRSortProje ct” which sorts tblStatusReport s by alphabetical Project order (first) then by reverse Date order (second).
“frmStaffEntry” VBA routines are:
Code:
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
Code:
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_Ent er() 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_Ent er() 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
Comment