Question

Query to tell me if a piece of equipment is due for service

Asked by: torttion

I have an access 2007 database I'm using to track my companies equipment and maintenance.  I've attached a pic of the relationship view to show what it entails.  I have a table, tblMaintenance where I track when equipment needs servicing.  It's related to tblService_Type.  TblMaintenance is set up so that it tracks an at what hour/mileage increments a unit needs servicing.  So, for instance, if a piece of equipment needed it's first (PM1) scheduled maintenance at 250 hrs and it's second (PM2) at 500 and it's third at 750 (PM3)...when it went over 750 it'd need PM1 and PM3 but not PM 2.  I have another table, tblAssets_Hrs_Miles where I track how many hours or miles my assets currently have, each day an entry is made with the assets ending miles or hours.  I have another table that tracks when an asset is serviced, tblService_Record.   I'd like to be able to run a query that tells me which assets are due for which services.  I was thinking of a calculation that did the following assuming the following values:

Asset#1:
  PM1 @ 250 hrs.  (A)
  PM2 @ 500 hrs.  (B)
  PM3 @ 750 hrs.  (C)

Service Record
  PM1 @ 256 hrs.   (D)
  PM1 @ 510 hrs.   (E)
  PM2 @ 510 hrs.   (F)

Current Hours: 706  (G)

For determining if it needs PM1:  IF G-E>A THEN PM1
For determining if it needs PM2:  IF G-F>B THEN PM2
etc...

I don't know if this is the correct way to go about it or not and on top of that, I have no idea how to do it since I don't know sql at all.  I also don't know if this is efficient since it'll have to go through each PM service type and each asset everytime it's run.  Any thoughts on the best way to do this?
 

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-11-02 at 16:51:52ID24865833
Topics

Microsoft Access Database

,

SQL Query Syntax

,

Access Coding/Macros

Participating Experts
2
Points
500
Comments
17

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Simple Php Mileage Expense Calculator
    I'm trying to make a quick mileage expense calculator but I don't quite know the syntax in php to get the values to automatically compute. Here is a site I have so far. It' very basic: http://www.lifeatcollege.com/dbtest/admin/mileage.php There are 2 ways to enter miles. 1...
  2. Adding the mileage field to a outlook calendar entry
    Hopefully this is an easy and straightforward one. I would like to add the mileage field to my calendar entries, ie when I book an appointment I can enter the mileage associated with that appointment. Any insights here would be appreciated. (Please note lots of searching MS...
  3. Equipment Records - Creating an "inheritance relationship"
    How do I create an inheritance relationship between the like measuring points in superior / sub equipment.
  4. Equipment mileage
    I have this problem to solve In code snippet is data of equipment put on 3 devices The top is the ok, the bottom is the data with late inserts a mileage gets calculated between the install and the current mileage on that device. a delta is then calculated and added to th...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: JMTinCLTPosted on 2009-11-02 at 17:30:04ID: 25725456

Well you could just do a query on tblAssets_Hrs_Miles and join it to tblAssets on Asset_ID where PM_at_Hrs_Mi => X

However, this is a pretty complicated question and not one that I can easily answer as it has many variables. I can say that your database layout seems acceptable.

 

by: harfangPosted on 2009-11-02 at 18:18:12ID: 25725607

If you don't know SQL at all, it's best to break the problem into pieces.

1) display an asset with the current mileage (G)

Create a new query, select tables tblAssets and tblAssets_Hrs_Miles. Select the field AssetID and just those fields needed to recognise the asset (as few as possible). From the second table, take only End_Of_Day_M???. Display the total row, leave "Group By" for all but the last, where you select Max.

This should provide (G). Save it, for example as qtotAssets_Current.

2) get last services

Create a new query on tblService_Record. Choose only three fields: Asset_ID, Service_Type_ID, and HrsMiles. Again, group on the first two, and use Max on the last one.

This provides (E) and (F). You can call it qtotService_Last

3) get the maintenance schedule

If the combination Asset_ID & Service_Type_ID is unique, you can skip this part. If not, proceed exactly like in 2), but for that table.

4) bring it together

In a new query, display qtotAssets_Current, qtotService_Last (linked on Asset_ID), and tblMaintenance (or the query you built for it -- linked on both Asset_ID and Service_Type_ID).

You should now have one row for each asset and each service type, with the values (G)(E)(A) in one row and (G)(F)(B) in the next. All that's left is then to compare them in an expression or in a criteria.

It's not as complicated as it seems. The SQL performing that in one query would be and then some.

Good luck!
(°v°)

 

by: torttionPosted on 2009-11-02 at 18:26:10ID: 25725628

Thanks harfang, I'll try it out in the morning and let you know how it turns out.

 

by: torttionPosted on 2009-11-03 at 07:26:51ID: 25729820

harfang,
     As far as I can tell, this is working great.  below is a picture of how I set up the query.  The only issue I can find in testing is that if a machine has never serviced it doesn't display.  It seems that in the qry I set up to display the last time a piece of equipment was serviced I'd need to tell it to display a 0 for any assets that does not have a service record.  How can I do this.

 

by: harfangPosted on 2009-11-03 at 08:34:11ID: 25730701

Of course, I should have anticipated that.

You can reverse the order of the sub-queries. First link on Maintenance, then on Service. Then double-click the links (the lines themselves), and specify that you want to see "all maintenance records", even if there are no matching services. The line should become an arrow.

As for the table 'service type', link it only once (remove the unnecessary link), in the new layout from 'maintenance'. You might have to change all links to arrows, if you get a message about "ambiguous joins":

    assets --> maintenance --> service
                                         \--> service type

Good luck!
(°v°)

 

by: torttionPosted on 2009-11-03 at 09:27:57ID: 25731305

I'm not entirely sure I understand.  I went through and re-did the joins and set all properties on each to show every record, etc...  I'm still getting the same result though, which works fine except for equipment that has never been serviced. Wouldn't the two other queries need to be altered (qryLast Service & qryassetCurrentHrsMiles) so that the data concerning a piece of equipment with no service record is available to qryWhenPMisDue?  Or, I could be entirely off-base :)  Below is the qry after I redid the joins.

 

by: harfangPosted on 2009-11-03 at 10:06:57ID: 25731699

It's good, but the arrows are in the wrong direction! You should also have a double link between 'maintenance' and 'last service', on both 'asset id' and 'service type id'. Finally, it's slightly better to link 'maintenance' to 'service type', so that the field is available even if there has been no service of that type.

Again, my feeble attempt at illustrating the idea:

    assets --> maintenance ==> service
                                         \--> service type

(°v°)

 

by: torttionPosted on 2009-11-03 at 10:19:16ID: 25731798

I just finally got your illistration attempt, I was reading it like flow chart, I think i've got it now.  However, the query still doesn't present the correct info.  It actually gives less information now, I'm not sure why.

 

by: harfangPosted on 2009-11-04 at 01:57:33ID: 25737766

What this query should show you is this.

* Every asset, with their highest 'hours miles' (first two columns)
* All records of tblMaintenance (provided there is at least one 'hours miles' record)
* The highest 'service' of the same type (or null if there was none)
* The service type.

You will then filter out records based on the Criteria: row. The expression might be more restrictive than you think, especially if you refer to fields that can be Null. Does the returned records seem OK without criteria? If yes, can you show the criteria you are using? If not do the subqueries return the expected records?

(°v°)

 

by: torttionPosted on 2009-11-04 at 12:09:38ID: 25743390

Below I've attached a screen shot of the qry results both without criteria and with.  It looks like it's displaying exactly what you described above without the criteria, but with the criteria it's not showing everything due for service.  I put the criteria under the service type field, if I put it anywhere else I get a 'data type mismatch' error.  Below is the criteria I've been using.  thanks again for all of you help, I really do appreciate it  

IIf(([MaxOfEnd_of_Day_MI_Hrs]-[MaxOfHrsMiles])>[PM_at_Hrs_Mi],[Service_Type])

 

by: torttionPosted on 2009-11-04 at 12:10:41ID: 25743401

Here are the results with the criteria

 

by: harfangPosted on 2009-11-04 at 14:39:05ID: 25744841

It's coming along fine. The last problem is the criteria.

The reason it fails has to do with the way Null is treated. Null isn't 0, and ever expression involving Null becomes Null (this is different from the way blank cells are handled in Excel). On the second row, asset 23, PM1

IIf(([MaxOfEnd_of_Day_MI_Hrs]-[MaxOfHrsMiles])>[PM_at_Hrs_Mi],[Service_Type])
IIf((600-Null)>250,'PM Number 1')
IIf(Null>250,'PM Number 1')
IIf(Null,'PM Number 1')
Null

And null is treated as a failure. To convert a column which can be Null to Zero, use the function Nz(): Nz(MaxOfHrsMiles).

I would put the criteria below the field PM_at_Hrs_MI:

    >= MaxOfEnd_of_Day_MI_Hrs - Nz(MaxOfHrsMiles)

Good luck!
(°v°)

 

by: torttionPosted on 2009-11-05 at 11:39:41ID: 25753089

I tried this but it didn't work.  It acutally only ended up displaying one record, the 5th one down on the table I posted above (24,550, , 750, PM Number 3).  However in messing around with this I found that if I don't have any criteria whatsoever I'm still not getting exactly what I should.  Below is a snapshot of qryLastService.  It displays two service records for asset number 10, one for PM1 and one for PM2.  Both should be displayed in qryWhenPMisDue, however, only the record of PM2 displays.  I'm not sure why it's doing this.  I thought perhaps I should solve this problem first.

When I tried the criteria you mentioned above, I had to change it slightly because I kept getting a syntax error.  I changed it to:
>=[MaxOfEnd_of_Day_MI_Hrs]-Nz([MaxOfHrsMiles])

Again, thatnks for you help in helping me solve this problem.

 

by: torttionPosted on 2009-11-05 at 12:22:56ID: 25753535

Also, I'm not sure if you wanted me to keep the criteria I had been using under the service type field or not.  But, if so, when I have both criteria in place, I don't get any results.  

 

by: harfangPosted on 2009-11-05 at 12:28:59ID: 25753620

You will see records from qryLastService only if there is a matching record in tblMaintenance. If there isn't no service of that type is required for the asset.

Could that be the problem?

> It acutally only ended up displaying one record, the 5th one down on the table I posted above

That's a clue, because it's the one row you don't want! (Still 200 miles to go...) I suppose the condition if the wrong way around. Have you tried '<=' instead of '>='?

(°v°)

 

by: torttionPosted on 2009-11-05 at 13:44:55ID: 25754390

I change it to <= and it works perfectly!  Thank you so much, I really do appreciate your time and patience!!!  Now I need to create a report out of this.  Keep any eye out for the questions I'm sure I'll have about that.  :)

 

by: harfangPosted on 2009-11-05 at 13:55:16ID: 25754484

You are most welcome!

If you have related questions, use the link "ask a related question" here. That way, I get an email notification, and other experts in the new question can refer back to this one if needed.

Thanks and success with your project!

(°v°)

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...