MS Access run query on form


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.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jeffrey CoachmanMIS LiasonCommented:
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...

ronnie10165Author Commented:
Thanks Jeff I can do the maths but how do I get the query to run on the form?
Jeffrey CoachmanMIS LiasonCommented:
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.

10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

ronnie10165Author Commented:
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.
Jeffrey CoachmanMIS LiasonCommented:
<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?


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ronnie10165Author Commented:
That's it, in the query itself..thanks
Jeffrey CoachmanMIS LiasonCommented:
ok  great

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.