Hi,
I'm trying to get MS Access to automatically move the cursor to the record near today's date within a subform in a project management database (frmvw_mileston es). The Main form (FRM_staff_proj ect) has the project information and it includes a subform (frmvw_mileston es) that has details about the important milestones within certain projects. The subform shows all the milestones for the fiscal year for the staff member. I want to move the cursor down within the form so that the staff member sees his/her current milestones upon opening the form instead of having to scroll down.
The following code almost works:
---------------
However, I need to modify this code so that it selects the maximum Milestone_Date for that staff member based on his/her id (ID_staff) instead of the maximum Milestone_Date for all staff members. I tried modifying the SELECT statement to following but it generates errors:
Any help would be appreciated. Attached are pictures of the main form (FRM_staff_proj ects) and the underlying query (qryvw_mileston es)
[IMGNOTHUMB]https://bytes.com/attachments/attachment/9432d1525201197/2018-05-01_10-46-45-swoop-project-form.jpg[/IMGNOTHUMB]
[IMGNOTHUMB]https://bytes.com/attachments/attachment/9433d1525201197/qryvw_milestone s.jpg[/IMGNOTHUMB]
I'm trying to get MS Access to automatically move the cursor to the record near today's date within a subform in a project management database (frmvw_mileston es). The Main form (FRM_staff_proj ect) has the project information and it includes a subform (frmvw_mileston es) that has details about the important milestones within certain projects. The subform shows all the milestones for the fiscal year for the staff member. I want to move the cursor down within the form so that the staff member sees his/her current milestones upon opening the form instead of having to scroll down.
The following code almost works:
Code:
Private Sub Form_Load() Dim db As DAO.Database Dim rst As DAO.Recordset Dim strSQL As String Dim TheDate As Date Set db = CurrentDb strSQL = "SELECT max(Milestone_Date) as Dte " & _ "FROM qryvw_milestones " & _ "WHERE Milestone_Date<=Now()" Set rst = db.OpenRecordset(strSQL) TheDate = rst.Fields(0) Me.Milestone_Date.SetFocus DoCmd.FindRecord TheDate Me.Milestone_Date.SetFocus End Sub
However, I need to modify this code so that it selects the maximum Milestone_Date for that staff member based on his/her id (ID_staff) instead of the maximum Milestone_Date for all staff members. I tried modifying the SELECT statement to following but it generates errors:
Code:
strSQL = "SELECT max(Milestone_Date) as Dte " & _ "FROM qryvw_milestones " & _ "WHERE (Milestone_Date<=now() " & _ "AND (tbl_pria_projects.ID_staff)=[Forms]![FRM_staff_projects]![ID_staff])"
[IMGNOTHUMB]https://bytes.com/attachments/attachment/9432d1525201197/2018-05-01_10-46-45-swoop-project-form.jpg[/IMGNOTHUMB]
[IMGNOTHUMB]https://bytes.com/attachments/attachment/9433d1525201197/qryvw_milestone s.jpg[/IMGNOTHUMB]
Comment