compsol1993
asked on
VBA Select Query Help Needed
Hello,
I have two tables in MSAccess
-Jobs [ JobID, JobDesc]
-JobsCompleted[JobID, JobTime, JobResult (Boolean)]
My goal is to create an MS Access Continuous Form with the following structure:
[Job Desc1] [JobResultToday] [JobResultYesterday] [JobResultTwoDaysAgo]
[Job Desc2] [JobResultToday] [JobResultYesterday] [JobResultTwoDaysAgo]
Where each result is a checkbox. Is there anyway to craft a query that produce this type of result?
I tried using the Form_Current() and changing the color of the checkboxes (couldn't change the 'check', and found it changed the color of all rows, not just the one I'm looking at.
Any other thoughts?
Thanks
I have two tables in MSAccess
-Jobs [ JobID, JobDesc]
-JobsCompleted[JobID, JobTime, JobResult (Boolean)]
My goal is to create an MS Access Continuous Form with the following structure:
[Job Desc1] [JobResultToday] [JobResultYesterday] [JobResultTwoDaysAgo]
[Job Desc2] [JobResultToday] [JobResultYesterday] [JobResultTwoDaysAgo]
Where each result is a checkbox. Is there anyway to craft a query that produce this type of result?
I tried using the Form_Current() and changing the color of the checkboxes (couldn't change the 'check', and found it changed the color of all rows, not just the one I'm looking at.
Any other thoughts?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
mbizup, thanks, that works great. You've got the points, but just one question.
Any advice for what I should do if a job is missed. It seems I need to bring the actual "Job" table into this, so that feeds the jobs, and then pull data from JobsCompleted Table
I modified your last WHERE statement to be:
WHERE IN (SELECT JobID From Job), but it produces all jobscompleted -- it doesn't just list each job 'once'.
Thanks again!
Any advice for what I should do if a job is missed. It seems I need to bring the actual "Job" table into this, so that feeds the jobs, and then pull data from JobsCompleted Table
I modified your last WHERE statement to be:
WHERE IN (SELECT JobID From Job), but it produces all jobscompleted -- it doesn't just list each job 'once'.
Thanks again!
Are you only looking for the last 3 days, or is that just an example?
Assuming that your JobTime field is actually a date, I believe you can do this with something like:
TRANSFORM Sum(tbl_JobsCompleted.JobR esult) AS SumOfJobResult
SELECT tbl_Jobs.JobDesc
FROM tbl_Jobs INNER JOIN tbl_JobsCompleted ON tbl_Jobs.JobID = tbl_JobsCompleted.JobID
WHERE (((DateDiff("d",[JobTime], Date()))<3 ))
GROUP BY tbl_Jobs.JobDesc
PIVOT DateDiff("d",[JobTime],Dat e());
This computes the difference between todays date and the JobTime field and limits it to today and the previous two days. You would then use this in a report, change the labels from 0, 1, and 2 to "Today", "Yesterday", "DayBefore" And then change the control types from text (which would display the numbers (0, -1) checkboxes. This would result in a query that looks like:
JobDesc 0 1 2
Job1 -1 0
Job2 -1 0 0
Job3 -1 0
Assuming that your JobTime field is actually a date, I believe you can do this with something like:
TRANSFORM Sum(tbl_JobsCompleted.JobR
SELECT tbl_Jobs.JobDesc
FROM tbl_Jobs INNER JOIN tbl_JobsCompleted ON tbl_Jobs.JobID = tbl_JobsCompleted.JobID
WHERE (((DateDiff("d",[JobTime],
GROUP BY tbl_Jobs.JobDesc
PIVOT DateDiff("d",[JobTime],Dat
This computes the difference between todays date and the JobTime field and limits it to today and the previous two days. You would then use this in a report, change the labels from 0, 1, and 2 to "Today", "Yesterday", "DayBefore" And then change the control types from text (which would display the numbers (0, -1) checkboxes. This would result in a query that looks like:
JobDesc 0 1 2
Job1 -1 0
Job2 -1 0 0
Job3 -1 0
ASKER
Thanks for the help everyone, the 1st posts code meets my needs nicely.
Each instance of a row in a continuous form is a clone of the form and inherits the "master" attributes so if you color controlA in an event of the current row, all instances of controlA take on the assigned color. For limited situations you can use Conditional Formatting which will apply to only a single row. With the form in design view, select the field you want to control and then click ConditionalFormatting in the ribbon.