473,386 Members | 1,720 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.

How do I pass parameters from VB6 to a Query in MS Access?

I have got a query in my MS Access database which requires 2 parameters. From my VB6 program, I need to call this MS Access Query by passing the 2 parameters dynamically. How can this be done?

And, thanking in advance...


************************************************** *******************************
"If an experiment works fine, something has gone wrong"
************************************************** *******************************
Sep 28 '06 #1
9 20589
CaptainD
135 100+
I have got a query in my MS Access database which requires 2 parameters. From my VB6 program, I need to call this MS Access Query by passing the 2 parameters dynamically. How can this be done?

And, thanking in advance...


************************************************** *******************************
"If an experiment works fine, something has gone wrong"
************************************************** *******************************
Do you have an Access Database that has a query in it, and you want to run that query?

VB programs are usually the "Front end" that can have an Access Database as a "Back end". You usually build the query in VB taking values from the form as your Parameters and then run the SQL statement against the database.
Sep 28 '06 #2
Anix
1
Hi CaptainD

I have a very similar problem....

I have an Access 2000 Query that expects 2 parameters. Currently when the query is run with Access pop-up windows request the parameters. However i would like to run this query from VB6.
So i need to call/run the query and pass it the 2 values.

Any help is much appreciated..

SJ
Oct 2 '06 #3
Hemant Pathak
92 Expert
Hi........................

it is so simple.... it is the part of my PMS(Production managment system) Project

Dim sQueryName As String
Dim rs As New ADODB.Recordset
Dim Com As New ADODB.Command
sQueryName = "STOCK_VIEW_G_TOTAL"
With Com
Set .ActiveConnection = Cnn
.CommandText = sQueryName
.CommandType = adCmdStoredProc
.Parameters.Append .CreateParameter("ENTER_ITEM_NAME", adVarChar, adParamInput, Len(CmbSType.Text), CmbSType.Text)
.Parameters.Append .CreateParameter("FINANCE_YEAR", adVarChar, adParamInput, Len(CStr(FNYear)), FNYear)
End With
set rs=com.excute
Oct 3 '06 #4
CaptainD
135 100+
Hi CaptainD

I have a very similar problem....

I have an Access 2000 Query that expects 2 parameters. Currently when the query is run with Access pop-up windows request the parameters. However i would like to run this query from VB6.
So i need to call/run the query and pass it the 2 values.

Any help is much appreciated..

SJ
I think you missed the point of the first answer. Access is a database program that provides you with an interface to the database as well as a means of creating a database. VB is a program that allows you to create an interface to a database. The database can be an MDB (Access database) DBF, SQL server etc. The query to pull information from the database can come from anywhere that can access the database. In VB you write the query and pass that to the database to return information to your VB application. So write you wuery in code getting your parameters from your application and join those parameters to the SQL string to be passed to the database.
Oct 3 '06 #5
Hemant Pathak
92 Expert
------------------------------------------------------------------------------------------
Note:
CmbSType.Text=send ur input in Query it is my Combo Box Value
FNYear= it string Value Like Sep/2006 Like this

i have the the two input of my access query.
---------------------------------------------------------------------------------------------
My Query
---------------
SELECT SM.ITEMNAME, FORMAT(Sum(IIf(FLAG='O',WEIGHT,0)),'0.000') AS OPENING, FORMAT(SUM(IIf(FLAG='P',WEIGHT,0)),'0.000') AS PURCHASE, FORMAT(SUM(IIF(FLAG='IFA',WEIGHT,0)),'0.000') AS TRANS_IN, FORMAT(SUM(IIF(FLAG='PR',WEIGHT,0)),'0.000') AS PUR_RETURN, FORMAT(SUM(IIF(FLAG='TF' OR FLAG='TO',Weight,0)),'0.000') AS DISPATCH, FORMAT(((VAL(OPENING)+VAL(PURCHASE)+VAL(TRANS_IN))-(VAL(PUR_RETURN)+VAL(DISPATCH))),'0.000') AS BALANCE
FROM StockMaster AS SM
WHERE (((SM.IType)=[ENTER_ITEM_NAME]) AND ((SM.Place)='Godown') AND (FYEAR=[FINANCE_YEAR]))
GROUP BY SM.ItemName;
--------------------------------------------------------------------------------------------------------------
i think it is a right think.
Oct 3 '06 #6
CaptainD
135 100+
Hi........................

it is so simple.... it is the part of my PMS(Production managment system) Project

Dim sQueryName As String
Dim rs As New ADODB.Recordset
Dim Com As New ADODB.Command
sQueryName = "STOCK_VIEW_G_TOTAL"
With Com
Set .ActiveConnection = Cnn
.CommandText = sQueryName
.CommandType = adCmdStoredProc
.Parameters.Append .CreateParameter("ENTER_ITEM_NAME", adVarChar, adParamInput, Len(CmbSType.Text), CmbSType.Text)
.Parameters.Append .CreateParameter("FINANCE_YEAR", adVarChar, adParamInput, Len(CStr(FNYear)), FNYear)
End With
set rs=com.excute
What is the advantage of running a query that resides in Access as opposed to just putting it (The SQL string) in your VB program?
Oct 4 '06 #7
CaptainD
135 100+
------------------------------------------------------------------------------------------
Note:
CmbSType.Text=send ur input in Query it is my Combo Box Value
FNYear= it string Value Like Sep/2006 Like this

i have the the two input of my access query.
---------------------------------------------------------------------------------------------
My Query
---------------
SELECT SM.ITEMNAME, FORMAT(Sum(IIf(FLAG='O',WEIGHT,0)),'0.000') AS OPENING, FORMAT(SUM(IIf(FLAG='P',WEIGHT,0)),'0.000') AS PURCHASE, FORMAT(SUM(IIF(FLAG='IFA',WEIGHT,0)),'0.000') AS TRANS_IN, FORMAT(SUM(IIF(FLAG='PR',WEIGHT,0)),'0.000') AS PUR_RETURN, FORMAT(SUM(IIF(FLAG='TF' OR FLAG='TO',Weight,0)),'0.000') AS DISPATCH, FORMAT(((VAL(OPENING)+VAL(PURCHASE)+VAL(TRANS_IN))-(VAL(PUR_RETURN)+VAL(DISPATCH))),'0.000') AS BALANCE
FROM StockMaster AS SM
WHERE (((SM.IType)=[ENTER_ITEM_NAME]) AND ((SM.Place)='Godown') AND (FYEAR=[FINANCE_YEAR]))
GROUP BY SM.ItemName;
--------------------------------------------------------------------------------------------------------------
i think it is a right think.
Only thing I see that might be a problem is your where cluase has items that are not in the Group by, but if it runs in Access that way, great.

I VB it will not prompt you for inputs the way Access does when it open. you need to pull the parameters from your VB form through input boxes or tect fields, combos, some means and place that in the query string.
Oct 4 '06 #8
Hemant Pathak
92 Expert
Hi...........

Q. 1 : What is Cnn?
Ans : yes u r right it is AdoConnection.
Like
Dim CNN as New ADODB.Connection
i think it it clear ur first quistion.

Q 2 How do you tell VB where the access.mdb is located?
Ans : Put ur mdb file in ur Exe path and call app.path it is return ur Current application path.

like ur mdb name=MyDatabase.mdb
dbpath=app.path & "\MyDatabase.mdb"

Q 3 : About Query?
Ans : When u call the query and not pass the proper parameter then vb error is raised some parameter is missing.

and u know when u create the query this time u well know to what is the parameter to paas.

and any problem..................
Oct 4 '06 #9
Only thing I see that might be a problem is your where cluase has items that are not in the Group by, but if it runs in Access that way, great.

I VB it will not prompt you for inputs the way Access does when it open. you need to pull the parameters from your VB form through input boxes or tect fields, combos, some means and place that in the query string.


Hi

I have created a Button called 'Reports' behind which a stored procedure is running with the help of wizard.If I click on Reports it will prompt for the start and end date.Once both dates are given a report will be generated.Now Am planning to do some modification like instead of prompting for the parameters am gonna create two text boxes with start and end date which should be passed to the stored procedure.Do I need to write stored procedure without wizard for passing arguments or else is there any other way?
Aug 19 '13 #10

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

Similar topics

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...
7
by: Zlatko Matić | last post by:
Let's assume that we have a database on some SQL server (let it be MS SQL Server) and that we want to execute some parameterized query as a pass.through query. How can we pass parameters to the...
3
by: Zlatko Matić | last post by:
Hello. I'm wondernig what is happennig whith saved pass-through queries nested in regular JET query if regular JET query just filtrates result by start/end date...Does pass-through query first...
0
by: Zlatko Matić | last post by:
Hi everybody! Recently I was struggling with client/server issues in MS Access/PostgreSQL combination. Although Access is intuitive and easy to use desktop database solution, many problems...
3
by: JezB | last post by:
I know I can use the querystring mechanism to pass simple parameters to a Page using Response.Redirect, but Im having problems getting this to work using Server.Transfer or Server.Execute - is this...
6
by: Woody Splawn | last post by:
I am using SQL Server 2000 as a back-end to a VS.net Client/Server app. In a certain report I use a view as part of the query spec. For the view, at present, I am querying for all the records in...
2
by: ILCSP | last post by:
Hello, I'm in the process of changing our 'normal' Access 2000 update queries to Update Pass Through Queries. We have a SQL server 2000 database and we're using an Access 2000 database as our...
9
by: skinnybloke | last post by:
Hi - I have 3 access queries which I run via 1 macro. Each of the queries now requires 2 parameters when they the run. The parameters are start and end dates. I have built the parameters...
1
by: Mayhem05 | last post by:
I have an Access 2003 database that I need to write some VBA code for to populate a table. The table is based on a query I have built in Access queries. Right now I have 2 parameters that are...
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 ...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
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
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.