MS Access run query on form

Posted on 2013-09-25
Medium Priority
Last Modified: 2013-09-25

I have an Access DB which stores parts in bins. As I enter a part I need to calculate it's volume and select a bin which has enough space to fit it in.

I have a query that uses a calculated field on the parts table to add up individual parts volume and compare that answer to the volume of the bin.

What I can't work out is how to get the current record's calculated field value and check if it will go in a bin's remaining volume.

Question by:ronnie10165
  • 4
  • 3
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 39523637
IF BinVolume-TotalVolumeOfAllParstInTheBin>=VolumeOf1Part  Then
    Part will fit
    part will not Fit
end if

Example: part Volume=3
6 parts=18Vol

bin Vol=21

So, ...
21vol-18vol=3vol, part will fit
21vol-12vol=4vol, Part will fit
21vol-20vol=1vol, Part will not fit

So as long as the remaining vol is greater that the Vol of 1 part, the part will fit.

There may be more to this, but that should be it basically...


Author Comment

ID: 39523639
Thanks Jeff I can do the maths but how do I get the query to run on the form?
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 39523650
Not sure if you want the query to run FROM the form (Open in a separate window)
Or if the query is the Recordsource for the form, and you need the result to appear in a field...?

For the query to run separately:
1. Create a button on the form
2. The code on the button onclick event will be:
    Docmd.OpenQuery "YourQueryName"

To use the query as a form's recordsource:
1. Test the query to see if it returning the correct values
2. Create a form using the query as the source

If this still is not what you want, then you will have to post a small sample database that demonstrates what you have.
Also post the explicit steps to use your sample db and see the issue.
Post the exact steps you need the user to perform.
Finally post a clear graphical example of the *exact* output you want.

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.


Author Comment

ID: 39523658
Ok I can see that is what I need, but how do I add the if..else logic. This would be easy for a webpage but I need it i the Access app for my customer.
LVL 74

Accepted Solution

Jeffrey Coachman earned 2000 total points
ID: 39523670
<Ok I can see that is what I need,>
You need what ?

I posted two suggestions, which is what you need?

<but how do I add the if..else logic.>
Add the if..else logic to what, ...again, please post a sample database folowing the steps I outlined, so I can see what you have already.

My guess is that it would be in a query like this:

SELECT BinVolume, TotalVolumeOfAllParstInTheBin, VolumeOf1Part,IIF(BinVolume-TotalVolumeOfAllParstInTheBin>=VolumeOf1Part,"Part Will Fit", "Part Will Not Fit") As PartFit
FROM YourTableOrQueryName

But again, I would really need to see a sample db to see what you has so far...
Sound fair?


Author Closing Comment

ID: 39523681
That's it, in the query itself..thanks
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 39523733
ok  great


Featured Post

7 new features that'll make your work life better

It’s our mission to create a product that solves the huge challenges you face at work every day. In case you missed it, here are 7 delightful things we've added recently to monday to make it even more awesome.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
If you need to implement application level security in an Access database application or other VBA code, I strongly encourage you to take advantage of Active Directory groups.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
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…

607 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