473,405 Members | 2,344 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,405 software developers and data experts.

help...how can I pass parameter to Access Query using VB

26
When I call this function Access gives me error msg "Too few parameters. Expected 3. [3061]" on the Set rstDAO = qryDef.OpenRecordset. Then I changed to
Set rstDAO = qryDef.OpenRecordset(dbOpenSnapshot, dbOpenSnapshot, dbOpenForwardOnly)

Now it gives me error "Invalid Arguments [3001]"...pls help...

here is my code:
Expand|Select|Wrap|Line Numbers
  1. Public Function GetTotalAmt(strAcct_Code As String) As Long
  2.    Dim currDB As DAO.Database
  3.    Dim rstDAO As DAO.Recordset
  4.    Dim qryDef As DAO.QueryDef
  5.    Dim strQry As String
  6.  
  7.    Set currDB = CurrentDb()
  8.    strQry = "Sum_Amt_CashierDirect"
  9.    Set qryDef = currDB.QueryDefs("Sum_Amt_CashierDirect")
  10.    qryDef.Parameters("acct_code") = "9ARTNC"
  11.    Set rstDAO = qryDef.OpenRecordset(dbOpenSnapshot, dbOpenSnapshot) '  ERROR MESSAGE EXPECTED 3 PARAMETERS
  12.  
  13.    MsgBox "[" & rstDAO![SumOfAMOUNT] & "]"
  14.  
  15.    GetTotalAmt = rstDAO![SumOfAMOUNT]
  16.  
  17.    'rstDAO.Close
  18.    'qryDef.Close
  19.  
  20. End Function
Aug 13 '08 #1
9 4334
Stewart Ross
2,545 Expert Mod 2GB
Hi. Please don't duplicate part of your post (see thread linked here) - it wastes the time of the expert volunteers who staff this site.

You are using a querydef object to allow parameter passing. In more normal circumstances OpenRecordset applies to the database object, not a querydef object. You can use the CurrentDb qualifier which is intrinsic in Access to refer to the currently-active database object. With it, the recordset open should become

Set rstDAO = Currentdb.OpenRecordset(strQry)

but if you need the parameter passing then retry your querydef based solution with OpenRecordset(strQry), as you have not supplied the correct arguments to OpenRecordset in the example you quote.

-Stewart
Aug 13 '08 #2
EVH316
26
thanks Stewart....sorry for double posting because I'm too desperate and nobody can help me....
Aug 13 '08 #3
EVH316
26
hi,

if I use:

Set rstDAO = Currentdb.OpenRecordset(strQry)

what I know, I need to use:

Set qryDef = currDB.QueryDefs("Sum_Amt_CashierDirect")

to pass parameter (acct_code-> parameter of my query and supplied them with "9ARTNC" value )

qryDef.Parameters("acct_code") = "9ARTNC"

how can I pass the parameter from my access query? if I do this?

Set rstDAO = Currentdb.OpenRecordset(strQry)

pls correct me if I'm wrong....pls help...

thanks
Aug 14 '08 #4
EVH316
26
...help please...

can anybody give me the syntax or example how can I implement the OpenRecordSet() method using MS Access query?

i'm still having "Too few parameters. Expected 3 [3061]"
Aug 14 '08 #5
EVH316
26
still waiting who can give solution to my problem
Aug 14 '08 #6
Stewart Ross
2,545 Expert Mod 2GB
Hi. As we have all already said, the error message does NOT relate to the syntax of the OpenRecordset method; it results from a failure to open the recordset, possibly related to references to form control values in the SQL of the underlying query.

Please post the SQL for the query you are trying to use OpenRecordset upon.

Thank you

-Stewart
Aug 14 '08 #7
EVH316
26
Hi Stewart,

Thanks for the response, here is the content of the query
Expand|Select|Wrap|Line Numbers
  1. SELECT dbo_SALFLDGDSN.ACCNT_CODE, 
  2.        dbo_SALFLDGDSN.PERIOD, 
  3.        dbo_SALFLDGDSN.JRNAL_NO, 
  4.        Sum(dbo_SALFLDGDSN.AMOUNT) AS SumOfAMOUNT, 
  5.        dbo_SALFLDGDSN.D_C
  6.   FROM dbo_qrySSRFADDDSN INNER JOIN dbo_SALFLDGDSN ON dbo_qrySSRFADDDSN.ADD_CODE = dbo_SALFLDGDSN.ACCNT_CODE
  7. GROUP BY dbo_SALFLDGDSN.ACCNT_CODE, 
  8.       dbo_SALFLDGDSN.PERIOD, 
  9.       dbo_SALFLDGDSN.JRNAL_NO, 
  10.       dbo_SALFLDGDSN.D_C
  11. HAVING ((  (dbo_SALFLDGDSN.PERIOD)  = Format(SunToSqlServerPeriod([Forms]![frmPayInvFileGen]![txtRepPeriod]),"General Number")) 
  12. AND ((dbo_SALFLDGDSN.JRNAL_NO)=[Forms]![frmPayInvFileGen]![txtJrnlNo]  ));
where:
SunToSqlServerPeriod() returns => "2008005"
[Forms]![frmPayInvFileGen]![txtJrnlNo] => 6735
Aug 15 '08 #8
Stewart Ross
2,545 Expert Mod 2GB
Hi. There are two form field references in the HAVING clause (the equivalent of a WHERE clause in a grouped query). Access is inconsistent in the way it treats form field references in such clauses, and there are known issues with their use (including the parameter error message arising with OpenRecordset). It is these problems that Adezii was referring to in his response.

When I use such form field references I do so through the use of a simple global function in VBA to fetch the value of the form field from the relevant form. Access has no problems with including function calls in SQL statements.

Open any public code module (any module shown in the Modules tab of the database), or create a new one if you don't have any. You can give it any suitable name (the default is Module 1).

Paste the following code in to the module and save the changes:

Expand|Select|Wrap|Line Numbers
  1. Public Function FormFieldValue(FormName As String, FieldName As String)
  2.     FormFieldValue = Forms(FormName).Controls(FieldName)
  3. End Function
Then try the revised HAVING part of the SQL for your query below, where the form field references are retrieved using the new function in place of direct references:

Expand|Select|Wrap|Line Numbers
  1. HAVING ((  (dbo_SALFLDGDSN.PERIOD)  = Format(SunToSqlServerPeriod(FormfieldValue("frmPayInvFileGen", "txtRepPeriod")),"General Number")) 
  2. AND ((dbo_SALFLDGDSN.JRNAL_NO)=FormFieldValue("frmPayInvFileGen", "txtJrnlNo")  ));
-Stewart
Aug 15 '08 #9
EVH316
26
Hi Stewart,

Thanks for your response....I'll try your solution to my problem...Thanks again..

EVH316
Aug 18 '08 #10

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

Similar topics

17
by: the other john | last post by:
This should be fairly basic but I can't think of how to do this and I'm running out of time! I am developing a picture gallery and I can't figure out how to select "one" picture from each...
3
by: Raghuraman | last post by:
Hai I have a designed Crystal report .rpt file which has 4 access tables .. After designing the report i put a parameter field which filteres the desired records quite naturally. Every thing...
5
by: Don Seckler | last post by:
I have an update query that runs when a report closes. I have several reports that will need to run the update query with diferent criteria. I'd like to simply make the criteria change in the...
5
by: Steve Patrick | last post by:
Hi All You guys are my last hope, despite spending money on books and hours reading them I still can not achieve the results I need. I have designed a database in Access 2000 based on 1 table,...
8
by: Tcs | last post by:
I've been stumped on this for quite a while. I don't know if it's so simple that I just can't see it, or it's really possible. (Obviously, I HOPE it IS possible.) I'm trying to get my queries...
3
by: Maciek Zywno | last post by:
Hi, I managed to do this by using a query and !! syntax, but it does not work with SPs. So I created a procedure with "@" to define a paraemter, but how can I pass a value to this procedure from...
2
by: Dud Bug | last post by:
I have a query in an Access db that prompts the user for info. (e.g. a primary key representing a company) before compiling the relevant table of results. This works fine in Access but I want to use...
2
by: Bill | last post by:
I have a 200 record database that includes a date/time field, AnnivDate, for a wedding anniversary. AnnivDate has nulls and some incorrect year data. I have been creating the Access database...
2
by: gumby | last post by:
I would like to call this stored procedure, but I am unable to pass parameters to the @Start and @End. Is thier a way to pass parameters to a pass through query from MS Access? SELECT ...
2
by: vijaykumardahiya | last post by:
Hello Sir, I have a simple Issue but It is not resolve by me i.e input parameter are not store in Ms-Access. I store the input parameter through Standard Action <jsp:useBean>. jsp:useBean call a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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
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...
0
tracyyun
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.