M
Melanie O
I'm trying to set a form's recordsource in VBA. This code seems to work:
WhereSQL = "tbl_TimeTracker.SystemID = Forms!subfrm_onesub!txt_name "
WhereSQL = WhereSQL & " AND tbl_TimeTracker.Date =
Forms!subfrm_onesub!txt_monday "
orderbySQL = "ORDER BY Date, Activity, SubActivity, Task "
Me.RecordSource = "SELECT tbl_TimeTracker.SystemID,
tbl_TimeTracker.Date, tbl_Activity.Activity, tbl_SubActivity.SubActivity,
tbl_Tasks.Task " & _
"FROM ((tbl_TimeTracker INNER JOIN tbl_Activity ON
tbl_TimeTracker.ActivityID = tbl_Activity.ActivityID) " & _
"INNER JOIN tbl_SubActivity ON tbl_TimeTracker.SubActivityID =
tbl_SubActivity.SubActivityID) " & _
"INNER JOIN tbl_Tasks ON tbl_TimeTracker.TaskID = tbl_Tasks.TaskID "
& _
"Where True and " & _
WhereSQL & orderbySQL
The problem is when I try to assign the variable CurrentDate and UserID to
text box values on the form instead of the references above as follows:
UserID = txt_name.Value
CurrentDate = txt_Monday.Value
I then substitute the appropriate Forms!form_name!field_name with the
variable name in the where statement. When the form opens, I am prompted for
the UserID, and the date restriction makes no records appear. I think the
date problem is related to the data type and/or lack of '#' around the date,
but I'm clueless about the UserID prompt. Any help on either issue would be
appreciated.
WhereSQL = "tbl_TimeTracker.SystemID = Forms!subfrm_onesub!txt_name "
WhereSQL = WhereSQL & " AND tbl_TimeTracker.Date =
Forms!subfrm_onesub!txt_monday "
orderbySQL = "ORDER BY Date, Activity, SubActivity, Task "
Me.RecordSource = "SELECT tbl_TimeTracker.SystemID,
tbl_TimeTracker.Date, tbl_Activity.Activity, tbl_SubActivity.SubActivity,
tbl_Tasks.Task " & _
"FROM ((tbl_TimeTracker INNER JOIN tbl_Activity ON
tbl_TimeTracker.ActivityID = tbl_Activity.ActivityID) " & _
"INNER JOIN tbl_SubActivity ON tbl_TimeTracker.SubActivityID =
tbl_SubActivity.SubActivityID) " & _
"INNER JOIN tbl_Tasks ON tbl_TimeTracker.TaskID = tbl_Tasks.TaskID "
& _
"Where True and " & _
WhereSQL & orderbySQL
The problem is when I try to assign the variable CurrentDate and UserID to
text box values on the form instead of the references above as follows:
UserID = txt_name.Value
CurrentDate = txt_Monday.Value
I then substitute the appropriate Forms!form_name!field_name with the
variable name in the where statement. When the form opens, I am prompted for
the UserID, and the date restriction makes no records appear. I think the
date problem is related to the data type and/or lack of '#' around the date,
but I'm clueless about the UserID prompt. Any help on either issue would be
appreciated.