The problem is I have a function that I've created and stored in a module. I call it as an expression (e.g. total: Function(parame ter)). I'm receiving the error 3061: too few parameters, expected 1. Now the query and database are already open so I'm not entirely sure of any connection strings I may need. I think part of the problem may be that the parameter I am using to call the function is part of the query. I am not sure how to come by this value before hand. I may need to split this into a two-stage query.
Advice greatly appreciated!
MS-Access SQL Query -
SELECT tblInventory.InventoryID, tblInventory.Food_Donations_ID, tblFoodDonor.[Donor Company], tblProductBrand.Brand_Name, tblFood_Category.Food_Category_ID, tblFood_Category.Food_Cat_Description, tblInventory!Num_Of_Containers*tblInventory!Weight_Per_Container AS Total_Poundage_From_Inv, totFdPoundage([tblInventory]![Food_Category_ID]) AS Total_Poundage_From_FD
-
FROM tblProductBrand INNER JOIN ((tblFood_Category INNER JOIN tblInventory ON tblFood_Category.Food_Category_ID = tblInventory.Food_Cat_ID) INNER JOIN (tblFoodDonor INNER JOIN tblFoodDonations ON tblFoodDonor.DonorID = tblFoodDonations.DonorID) ON tblInventory.InventoryID = tblFoodDonations.InventoryID) ON tblProductBrand.Brand_ID = tblInventory.Product_Brand_ID
-
WHERE (((tblInventory.Distribution_completed)=False));
-
My Function 8 2992 NeoPa 32,573
Recognized Expert Moderator MVP
No definitive answers, but I'd consider running the query without the function call to start with and see what shows. The parameter is defined as an Integer, so there must be no missing records, and the field passed must also be Integer (It is most usual for ID type fields to be defined as Longs).
See where this gets you. You may need to progress from there to debugging your actual code. Do it first without the query. See Debugging in VBA for help with debugging.
ChipR 1,287
Recognized Expert Top Contributor
What does this do?
lbsContainer = rsfh("Bakery")
ChipR 1,287
Recognized Expert Top Contributor
Case 8 is missing a parameter.
strsql = "SELECT FROM ...
@ChipR
According to my reading on recordsets, it should take the value of that field and place it in the lbsContainer variable.
ChipR 1,287
Recognized Expert Top Contributor
Sorry, but this is bothering me. The purpose of Select Case is to make your life easier. - strSQL = "Select "
-
Select Case fcat
-
Case 0
-
strSQL = strSQL & "Bakery "
-
Case 1
-
strSQL = strSQL & "Dairy "
-
Case 2
-
strSQL = strSQL & "Fruit "
-
...
-
Case Else
-
MsgBox "Invalid Category!"
-
End Select
-
strSQL = strSQL & "FROM tblFoodDonations WHERE " & _
-
"tblFoodDonations.FoodDonationsID = qryCurr_Inv.Food_Donations_ID"
-
Set rsfh = CurrentDb.OpenRecordset(strSQL)
-
...
That being said, this seems like a job for DLookup.
@ChipR
Ok, I've written up a DLookup function and it seems to be correctly formatted yet it gives me a data type mismatch for the criteria section. Can you let me know if I am giving the correct parameters? -
Public Function totLBS(fdreceipt As String, fcat As String) As Long
-
-
-
Dim numLbsContainer As Long
-
Dim strCriteria As String
-
-
strCriteria = "FoodDonationsID =" & fdreceipt
-
numLbsContainer = DLookup(fcat, "tblFoodDonations", strCriteria)
-
-
totLBS = numLbsContainer
-
End Function
When Debugging the fcat is "Meat" which is the correct string for the category I want to look up in the tblFoodDonation s category.
The strCriteria in my test case comes out to "FoodDonationsI D=80012" which appears to be the correct format when going by the link you gave me.
I think the problem is alllllmost solved.
Thanks for all the help!
Nevermind, I figured out where my formatting was wrong. I'll repost the code below in case anyone else has DLookup trouble. -
Public Function totLBS(fdreceipt As String, fcat As String) As Long
-
-
-
Dim numLbsContainer As Long
-
Dim strCriteria As String
-
-
strCriteria = "[FoodDonationsID] =" & "'" & fdreceipt & "'"
-
numLbsContainer = DLookup("[" & fcat & "]", "tblFoodDonations", strCriteria)
-
-
totLBS = numLbsContainer
-
End Function
-
-
I appreciate all the help I received from this forum, special thanks to ChipR & NeoPa.
NeoPa 32,573
Recognized Expert Moderator MVP @Cintury
Is the field you want returned called [fcat] or [Meat]. If the former, then you would need the following instead : - numLbsContainer = DLookup("[fcat]", "tblFoodDonations", strCriteria)
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: alessia |
last post by:
hi,
I have a query that visualizes me, according to some criterions from
me inserted, name , Surname , Address , phone
ok..
Now, through a button, positioned in a Form,
I have to only export from this query the field telephone in a text
file
the name of the text file I would like to choose me...
|
by: deko |
last post by:
I need a way to create a table with a programmatically defined name. I have a
Make Table query that will create the table with the name that I put in the
query, but I don't know how to (or if I can) use a function to pass the table
name into the query.
Here is the basic form of the Mke Tble query:
SELECT TxDate, Amount, Tx_ID, TxAcctName, INTO FROM
tblTxJournal;
|
by: Richard Hollenbeck |
last post by:
I have a crosstab query that shows all the scores of all the activities of
all the students in all courses, with the students being in the rows and the
activities being in the columns and the scores being in the intersections of
the rows and columns.
I also have a report based on this query that, depending on the activity
names, will dynamically insert the field names into the column labels, so
that I don't have to make a new report...
|
by: MLH |
last post by:
Suppose I have this simple SQL string...
SELECT tblDrivers.DriverID, tblDrivers.DName
FROM tblDrivers
WHERE (((tblDrivers.DName) Like "N*"))
ORDER BY tblDrivers.DriverID;
And suppose that its not a saved querydef -
just an SQL string that I cooked up in code
and assigned to a global var strMySQL.
|
by: Kelii |
last post by:
I've been trying to get this piece to work for a few hours, but have
given up. I hope someone out there can help, I think the issue is
relatively straightforward, but being a novice, I'm stumped. Below you
will find the code I've written and the error that results. I'm hoping
that someone can give me some direction as to what syntax or parameter
is missing from the code that is expected by VBA.
Overview:
I'm trying to copy calculated...
| |
by: Richard Hollenbeck |
last post by:
I am very sorry about the (almost) re-post, but you will see that my first
question wasn't very clear; I have another question I posted this morning
called, "in DAO: Run time error 3061 Too few parameters...."
I have read many articles on the web about how to make a dynamic report
based on a cross-tab query. But for some reason mine never works right.
First, my saved query's criteria is the data in an open form's combo box.
So the...
|
by: QCLee |
last post by:
Sir can you help me to transfer my Access Query to MS excel? i have a
command button on the form to export the parameter query named
"HVACWindwardQuery" to excel spreadsheet and i got the codes from
searching on the internet and books but the problem is when i run the
command button "Export" it just only open the Blank Spreadsheet, no
data at all that it came from my query named "HVACWindwardQuery" and
there's an error on it...
|
by: kcdoell |
last post by:
Hello:
What is the best way to stop a report from running if the query is empty? Currently, I have a form that has a command button on it. The user has to make selections from 3 combo boxes on the form and then via the cmdbutton the report opens in preview mode. I want to stop it from executing if the query is empty. I thought I could do this by checking the record count by the following code but I error out with the following message:
...
|
by: raghuvendra |
last post by:
Hi
I have a jsp page with 4 columns: namely Category name , Category order, Input field and a submit button.
All these are aligned in a row. And Each Category Name has its corresponding Category order, Input field and a submit button.
The Category name is being fetched from the oracle db along with the corresponding Category order.
In the corresponding input field (text box) the user enters a new category order which gets stored in the...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |