473,386 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

What is the syntax for getting a function's result into a query's criteria?

stonward
145 100+
Hello Again All,

Forgive me as I try to be brief:

I am using a modified version of Allen Browne's excellent 'onhand' function for calculating stock levels 'on-the-fly'.

The function works perfectly, however I need to show stocklevels for a number of items on my 'home' form and found that the onhand function is way too slow to allow that. My solution is to 'reflect' the onhand results via a query into my products table, and this works well, since I'm simply viewing the data.

But when I perform a transaction, I can only get the onhand function to work if I recalculate all of my products, rather than just the ones in the transaction - and that is slow - at least 30 seconds.

I have tried my preferred method of SQL in the module code, and running a query of the same from the code, but zero records are updated. Here is the SQL I have been using - can you see an error?

Expand|Select|Wrap|Line Numbers
  1. Dim strSQL as String
  2. strSQL = "UPDATE Products SET Products.Stocklevel = (onhand([productID])) " & vbCrLf & _
  3. "WHERE (((Products.Stocklevel) = [forms]![frm_PurchaseDetails]![productID]));"
  4. DoCmd.SetWarnings False
  5. DoCmd.RunSQL(strSQL)
  6. DoCmd.SetWarnings True
Products = Products table, frm_PurchaseDetails = subform to frm_Purchases, linked of course.

If you don't know the 'onhand' function, you simply provide the ProductID and an optional date to get the stock calculation for that date.

The SQL for the query that works (but calculates all products) is;
Expand|Select|Wrap|Line Numbers
  1. UPDATE Products SET Products.Stocklevel = (onhand([productID]));
And a clue may be that the above will not work as SQL in the module, only as running the query.

Sorry it appears so drawn out...

Best regards,
Stonward
Feb 5 '13 #1
4 1513
NeoPa
32,556 Expert Mod 16PB
The WHERE clause from the SQL in the first code block treats Products.Stocklevel as a ProductID, whereas the working, but slow, SQL from the second block treats it in a way that makes more sense - as a StockLevel.
Feb 5 '13 #2
stonward
145 100+
Ha! Spotted NeoPa. And so obvious...now.

Altered to where clause from stocklevel to productid and the update works, but is still very slow. Am I missing something more fundamental I should be looking at?

Thanks for finding that; I couldn't find it.

Regards

Stonward
Feb 5 '13 #3
stonward
145 100+
Hi again.

Something is wrong with the update SQL/query (above). I altered the SQL to take account of what looked like a glaring error that Neopa found. The stocklevels get updated, but i also get a parameter query input box asking me for input. Clicking OK (no input) updates the stocklevel.

But when I look at the (update) query that the SQL is based upon, I can see no errors. The
Expand|Select|Wrap|Line Numbers
  1. Products.Stocklevel
that appears to be an error is the field and table that are being updated:

Field: Stocklevel
Table: Products
Update To: (onhand([productID]))
Criteria: [forms]![frm_Purchases]![frmPurchaseDetails].[form].[productID]

Can anyone see an error in the above? It should update one stocklevel record of a product with the product ID shown on the PurchaseDetails subform.

It's starting to look easier to simply add/subtract the transaction quantity from the current stocklevel!

Thanks guys,

stonward
Feb 5 '13 #4
NeoPa
32,556 Expert Mod 16PB
Stonward:
Am I missing something more fundamental I should be looking at?
The only obvious thing I see is that you are calling a VBA function. I'm guessing the function needs to navigate to the correct record every time it's called. This is on top of opening and closing a recordset and the interpreter interpreting every line of VBA code in it. I wouldn't expect this to be at all trivial.

PS. As for the new question I suggest you post it in its own thread and include the actual SQL code sent to the Jet SQL engine. Feel free to post a link in here to the new thread if you like, but I expect I'll see it somewhen shortly anyway.
Feb 5 '13 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Alistair | last post by:
hello again people... Access2000, IIS6, win XP pro I have a form where users can enter search criteria for various products. now, if this form has 2 fields, colour and size (it wil have more...
3
by: colmobrien | last post by:
Help Needed ms access 2000 I have a table where one field is the year end monthr (January, February,........, December) and another field is the year end day (1,2,3,........,31) i want to...
2
by: Matthew | last post by:
Hey , I have built a query which takes values from unbounded fields on a form, and it all works except for one thing. I have a few fields in my query that are dates. I also have a start and...
0
by: Greg Strong | last post by:
Hello All, In the past I've used a combo box with the 'row source' being an Access SQL union query to select "All" or 1 for only 1 criteria in a query. An example is as follows: SELECT 0 As...
3
by: acdevteam | last post by:
Hello Everyone, We are a dev team very new to Access, and so far we have gotten excellent support from this group. We have a question about writing a query. Here is the situation: We have a...
3
by: mukeshhtrivedi | last post by:
Hi Gurus, I have created simple query as SELECT QUOTES.DATE, QUOTES.QUOTENO, QUOTES.SALESREP, QuoteItem.ITEM, QUOTES., QUOTES.CUSTOMER, QUOTES.AMOUNT, QUOTES., QUOTES.DivisionID,...
7
by: bryant | last post by:
Hi all. I am new to ASP and working in Expression Web. The following query displays the information I need in the gridview for a single record. SELECT "OE_HDR"."ORD_NO", "OE_HDR"."CUST_NAM",...
15
by: Michael R | last post by:
Hello forum! I have this question: I have a query with a column that uses this criteria: (IIfCustomerType()<>3,fCustomerType()) where fCustomerType() is a function result. But this...
10
by: Trevor2007 | last post by:
I have a query that setting date from and date to from form values works: >=!! And <=!! but now I am trying to add another peramiter to pass in adition to above and now it doesn't work, I get...
0
Walt in Decatur
by: Walt in Decatur | last post by:
I have a form which is tied to a table with data for equipment belonging in a particular space (tbl_equpment_data). This form is actually a subform on a main form which also deals with other data...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.