Solved

VBA Select Query Help Needed

Posted on 2013-12-12
5
450 Views
Last Modified: 2013-12-13
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
0
Comment
Question by:compsol1993
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 39715661
Try using this as the recordsource for your continuous form:

SELECT a.JobID, a.JobDesc, a.JobResult AS JobResultToday, 
(SELECT b.JobResult FROM JobsCompleted b WHERE Format(b.JobTime, 'yyyymmdd') = Format(Date() -1 , 'yyyymmdd') AND a.JobID = b.JobID) AS JobResultYesterday,
(SELECT c.JobResult FROM JobsCompleted c WHERE Format(c.JobTime, 'yyyymmdd') = Format(Date() -2 , 'yyyymmdd') AND a.JobID = c.JobID) AS JobResultTwoDaysAgo
FROM JobsCompleted a 
WHERE Format(a.JobTime, 'yyyymmdd') = Format(Date()  , 'yyyymmdd')

Open in new window

0
 
LVL 38

Expert Comment

by:PatHartman
ID: 39717032
You can use a crosstab query to "pivot" this data.

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.
0
 

Author Comment

by:compsol1993
ID: 39717327
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!
0
 
LVL 48

Expert Comment

by:Dale Fye
ID: 39717345
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.JobResult) 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],Date());

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
0
 

Author Closing Comment

by:compsol1993
ID: 39717590
Thanks for the help everyone, the 1st posts code meets my needs nicely.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month9 days, 10 hours left to enroll

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question