We help IT Professionals succeed at work.

Chante subform recordsource from Unbound Main form

Sandra Smith
Sandra Smith used Ask the Experts™
on
I have form that users will enter their tasks for each day.  For the txtDate control, in the after update event, I need to have two sub-forms have their recordsource change to present all records that are associated with the TimeSheetID for that date.  However, I can't seem to get the recordsource change to work.  I need to separate the select statemetns also based on by time of task, VAR and CON.


Sandra

Private Sub CompletedTasks( lngTSID As Long)
Dim strSelectVAR As String
Dim strSelectCON As String

strSelectVAR = "SELECT CompletedID, TaskID, TaskTime, TimeCode, EndTime, Description, TSID, StopWatch " & _
    "FROM TblCompletedTask " & _
    "WHERE TblCompletedTask.TaskID Like '*VAR*' AND TblCompletedTask.TSID = " & lngTSID & " "
   
strSelectCON = "SELECT CompletedID, TaskID, TaskTime, TimeCode, EndTime, Description, TSID, StopWatch " & _
    "FROM TblCompletedTask " & _
    "WHERE TblCompletedTask.TaskID Like '*CON*' AND TblCompletedTask.TSID = " & lngTSID & " "


Me.sfrmCompletedTaskVAR.RecordSource = strSelectVAR
Me.sfrmCompletedTaskCON.RecordSource = strSelectCON

Me.Form.sfrmCompletedTaskVAR.Refresh
Me.Form.sfrmCompletedTaskCON.Refresh

Me.Refresh

End Sub
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2012
Top Expert 2013
Commented:
You need the .Form property:


Me.sfrmCompletedTaskVAR.Form.RecordSource = strSelectVAR
Me.sfrmCompletedTaskCON.Form.RecordSource = strSelectCON
Most Valuable Expert 2012
Top Expert 2013

Commented:
And the refreshes should be requeries, but changing the recordsource should requery the subforms automatically - making those lines unneeded (so try removing them).

Finally - if you haven't already, set some breakpoints in the code and verify that the correct TSID is indeed being passed to that procedure.
Sandra SmithRetired

Author

Commented:
Yes, when I was using FORM, I had it originally in the wrong place, thank you.

Sandra