yddadsjd95
asked on
Use code behind command button in subform to change recordsource for sub-subform
Good Day All, I am working on a form that keeps track of estimates for a service company. There is an initial estimate and then the final estimate. The subform identifies certain dates - Estimate Date, Start Date, etc, along with the first estimate total and final estimate total. Then there is a sub-subform (form in a subform) that allows the user to enter the service items that make up the estimate and there is a yes/no field that identifies if service item is for first estimate. Once the final estimate has been entered into the sub-subform (it may or may not be the same as the first estimate), I want the user to be able to click a button on the subform to determine which estimate is reflected in the sub-subform.
I guess I need to create code that will change the record source for the underlying query in the sub-subform. It will either be for all records where FirstEstimate = Yes or FirstEstimate = No. I have created two command buttons - "Click to View First Estimate" and "Click to View Final Estimate". I want to be able to place code behind these buttons to alter the recordsource for the sub-subform that shows the service items. Any suggestions will be greatly appreciated.
Here is the current SQL that shows all of the records:
SELECT tblServOrderEstimate.ServO rderEstima teID, tblServOrderEstimate.ServO rderID, tblServOrderEstimate.Amoun t, tblServOrderEstimate.TreeT ypeID, tblTreeType.TreeType, tblServiceType.ServiceType , tblServOrderEstimate.Servi ceTypeID, tblServOrderEstimate.Initi alEstimate
FROM tblTreeType INNER JOIN (tblServiceType INNER JOIN (tblServOrder INNER JOIN tblServOrderEstimate ON tblServOrder.ServOrderID = tblServOrderEstimate.ServO rderID) ON tblServiceType.ServiceType ID = tblServOrderEstimate.Servi ceTypeID) ON tblTreeType.TreeTypeID = tblServOrderEstimate.TreeT ypeID;
FYI, I am running XP and Access 2002 in 2000 mode.
Thanks in advance,
David
I guess I need to create code that will change the record source for the underlying query in the sub-subform. It will either be for all records where FirstEstimate = Yes or FirstEstimate = No. I have created two command buttons - "Click to View First Estimate" and "Click to View Final Estimate". I want to be able to place code behind these buttons to alter the recordsource for the sub-subform that shows the service items. Any suggestions will be greatly appreciated.
Here is the current SQL that shows all of the records:
SELECT tblServOrderEstimate.ServO
FROM tblTreeType INNER JOIN (tblServiceType INNER JOIN (tblServOrder INNER JOIN tblServOrderEstimate ON tblServOrder.ServOrderID = tblServOrderEstimate.ServO
FYI, I am running XP and Access 2002 in 2000 mode.
Thanks in advance,
David
I don't see the field FirstEstimate in your SQL
ASKER
Thanks Guys,
Jim, does the Select statement include the SQL with a where statement at the end. I assumed that I would select the same fields form the original SQL and add the where statement, so I tried this:
Me.frmServOrderEstimates.F orm.Record Source = "SELECT tblServOrderEstimate.ServO rderEstima teID, tblServOrderEstimate.ServO rderID, tblServOrderEstimate.Amoun t, tblServOrderEstimate.TreeT ypeID, tblTreeType.TreeType, tblServiceType.ServiceType , tblServOrderEstimate.Servi ceTypeID, tblServOrderEstimate.Initi alEstimate _
FROM tblTreeType INNER JOIN (tblServiceType INNER JOIN (tblServOrder INNER JOIN tblServOrderEstimate ON tblServOrder.ServOrderID = tblServOrderEstimate.ServO rderID) ON tblServiceType.ServiceType ID = tblServOrderEstimate.Servi ceTypeID) ON tblTreeType.TreeTypeID = tblServOrderEstimate.TreeT ypeID where tblServOrderEstimate.Initi alEstimate = -1;"
------------^SQL for 1st or initial estimate
But Access gave me the compile error - Expected: end of statement - and it highlighted FROM in the SQL.
Jeff, I am sorry, the yes/no field for the first estimate is named InitialEstimate.
Further guidance will be appreciated.
David
Jim, does the Select statement include the SQL with a where statement at the end. I assumed that I would select the same fields form the original SQL and add the where statement, so I tried this:
Me.frmServOrderEstimates.F
FROM tblTreeType INNER JOIN (tblServiceType INNER JOIN (tblServOrder INNER JOIN tblServOrderEstimate ON tblServOrder.ServOrderID = tblServOrderEstimate.ServO
------------^SQL for 1st or initial estimate
But Access gave me the compile error - Expected: end of statement - and it highlighted FROM in the SQL.
Jeff, I am sorry, the yes/no field for the first estimate is named InitialEstimate.
Further guidance will be appreciated.
David
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Jim, sometimes all I can do is laugh when I learn something new in Access. I had quite a few compile errors trying make certain that all of the tables were identified correctly, but in the end, it did what you told me it would do. Plus I did not need the requery function.
Thanks again and have blessed weekend as you have blessed my day,
David
Thanks again and have blessed weekend as you have blessed my day,
David
Nice Jim..
An alternative..lol..late in the game I know.
if the recordsource of your form shows all records then a filter would have worked as well
Me.Filter = "[InitialEstimate] = -1"
Me.FilterOn = True
Me.Filter = "[InitialEstimate] = 0"
Me.FilterOn = True
to clear
me.FilterOn = False
Enjoy!! the weekend.
J
An alternative..lol..late in the game I know.
if the recordsource of your form shows all records then a filter would have worked as well
Me.Filter = "[InitialEstimate] = -1"
Me.FilterOn = True
Me.Filter = "[InitialEstimate] = 0"
Me.FilterOn = True
to clear
me.FilterOn = False
Enjoy!! the weekend.
J
Me.YourSubSubformControlNa
Me.YourSubSubformControlNa
End Sub