473,382 Members | 1,407 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,382 software developers and data experts.

Queries with Parameters

Supposing I wanted to do something like this:

Set rsB = db.OpenRecordset("qryStuff")

only qryStuff required parameters? How do I pass the parameter values to the query?
Thanks.
Nov 13 '05 #1
4 3429
You can assign values to the Parameters of the QueryDef before you
OpenRecordset:
Dim qdf As QueryDef

Set qdf = dbEngine(0)(0).QueryDefs("qryStuff")
qdf.Parameters("SomeParameter") = 4
Set rsB = qdf.OpenRecordset()

Another alternative is to just build the SQL statement dynamically instead
of worrying about saving a QueryDef with parameters.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Weaver" <we*****@verizon.net> wrote in message
news:66**************************@posting.google.c om...
Supposing I wanted to do something like this:

Set rsB = db.OpenRecordset("qryStuff")

only qryStuff required parameters? How do I pass the parameter values to
the query?
Thanks.

Nov 13 '05 #2
Thanks again Allen. But I'm not clear on a couple of things here.

Whats with this part:

dbEngine(0)(0).

I'm not familiar with that syntax.

Also, how do I cause the form to display the recordset that we're
manipulating here? Is it just:

SomeForm.Recordset = rsB
Chris.

"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message news:<41**********************@per-qv1-newsreader-01.iinet.net.au>...
You can assign values to the Parameters of the QueryDef before you
OpenRecordset:
Dim qdf As QueryDef

Set qdf = dbEngine(0)(0).QueryDefs("qryStuff")
qdf.Parameters("SomeParameter") = 4
Set rsB = qdf.OpenRecordset()

Another alternative is to just build the SQL statement dynamically instead
of worrying about saving a QueryDef with parameters.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Weaver" <we*****@verizon.net> wrote in message
news:66**************************@posting.google.c om...
Supposing I wanted to do something like this:

Set rsB = db.OpenRecordset("qryStuff")

only qryStuff required parameters? How do I pass the parameter values to
the query?
Thanks.

Nov 13 '05 #3
dbEngine is the top of the tree in the DAO object model - the library that
Access is based on internally. Details and examples in:
DAO: Data Access Objects
at:
http://members.iinet.net.au/~allenbrowne/ser-04.html

If this is heading for a form, you could set the RecordSource of the form to
the changed query, but you don't really need the query. Instead, just build
the SQL string and assign it to the form's RecordSource. Example:
Dim strSql as String
strSql = "SELECT * FROM MyTable WHERE SomeField = 4;"
Me.RecordSource = strSql

Alternatively, you could set the Filter property of the form instead of
worrying about the parameters at all.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Weaver" <we*****@verizon.net> wrote in message
news:66**************************@posting.google.c om...
Thanks again Allen. But I'm not clear on a couple of things here.

Whats with this part:

dbEngine(0)(0).

I'm not familiar with that syntax.

Also, how do I cause the form to display the recordset that we're
manipulating here? Is it just:

SomeForm.Recordset = rsB
Chris.

"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message

news:<41**********************@per-qv1-newsreader-01.iinet.net.au>...
You can assign values to the Parameters of the QueryDef before you
OpenRecordset:
Dim qdf As QueryDef

Set qdf = dbEngine(0)(0).QueryDefs("qryStuff")
qdf.Parameters("SomeParameter") = 4
Set rsB = qdf.OpenRecordset()

Another alternative is to just build the SQL statement dynamically
instead
of worrying about saving a QueryDef with parameters.
"Weaver" <we*****@verizon.net> wrote in message
news:66**************************@posting.google.c om...
> Supposing I wanted to do something like this:
>
> Set rsB = db.OpenRecordset("qryStuff")
>
> only qryStuff required parameters? How do I pass the parameter values
> to
> the query?
>
>
> Thanks.

Nov 13 '05 #4
Filter is the way I'd gone from the beginning. Somehow I thought that
a parameterized query would be more efficient. I'll stay with the
Filter; it works.

In regard to dbEngine, it's the (0) (0) part that had me puzzled.

I am posting another question to this forum regarding a far more
generic question that has me stymied. I'll probably call it 'Posting
error'. Have a look if you get the chance.

Thanks,

Chris.

"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message news:<41***********************@per-qv1-newsreader-01.iinet.net.au>...
dbEngine is the top of the tree in the DAO object model - the library that
Access is based on internally. Details and examples in:
DAO: Data Access Objects
at:
http://members.iinet.net.au/~allenbrowne/ser-04.html

If this is heading for a form, you could set the RecordSource of the form to
the changed query, but you don't really need the query. Instead, just build
the SQL string and assign it to the form's RecordSource. Example:
Dim strSql as String
strSql = "SELECT * FROM MyTable WHERE SomeField = 4;"
Me.RecordSource = strSql

Alternatively, you could set the Filter property of the form instead of
worrying about the parameters at all.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Weaver" <we*****@verizon.net> wrote in message
news:66**************************@posting.google.c om...
Thanks again Allen. But I'm not clear on a couple of things here.

Whats with this part:

dbEngine(0)(0).

I'm not familiar with that syntax.

Also, how do I cause the form to display the recordset that we're
manipulating here? Is it just:

SomeForm.Recordset = rsB
Chris.

"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message

news:<41**********************@per-qv1-newsreader-01.iinet.net.au>...
You can assign values to the Parameters of the QueryDef before you
OpenRecordset:
Dim qdf As QueryDef

Set qdf = dbEngine(0)(0).QueryDefs("qryStuff")
qdf.Parameters("SomeParameter") = 4
Set rsB = qdf.OpenRecordset()

Another alternative is to just build the SQL statement dynamically
instead
of worrying about saving a QueryDef with parameters.
"Weaver" <we*****@verizon.net> wrote in message
news:66**************************@posting.google.c om...
> Supposing I wanted to do something like this:
>
> Set rsB = db.OpenRecordset("qryStuff")
>
> only qryStuff required parameters? How do I pass the parameter values
> to
> the query?
>
>
> Thanks.

Nov 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: ahokdac-sql | last post by:
Hi, I'm adapting access queries to sql server and I have difficulties with the following pattern : query1 : SELECT * FROM Query2 WHERE A=@param1 query 2: SELECT * FROM Table2 WHERE B=@param2 ...
1
by: Roger Green | last post by:
I have inherited a complex database that has many dozens of queries that derive data from a people table. I now need to be able to run these queries (from within a significant number of forms)...
9
by: Dom Boyce | last post by:
Hi First up, I am using MS Access 2002. I have a database which records analyst rating changes for a list of companies on a daily basis. Unfortunately, the database has been set up (by my...
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...
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...
2
by: deko | last post by:
Is it possible to build a parameterized query from another parameterized query? I've tried two variations of this and can't seem to get it to work (using DAO). Any suggestions welcome! I...
2
by: Dirk Vervecken | last post by:
Hi i've got an application in dotnet that uses queries from an Access database. Now most of the common select statements return the desired data, however, one the queries requires a parameter....
2
by: Roy | last post by:
Hey all, Here's a small VB codeblock that connects to a database and uses 2 SQL queries then forms a relation for a master/detail view on the aspx side: Private Sub Binddata(ByVal name As...
4
by: =?Utf-8?B?Sm9uIEphY29icw==?= | last post by:
For MS SQL Server... I am used to declaring local variables in my SQL queries... Declare @MyInt int, @MyChar varchar(33) Parameters were idenfitied with a colon... Where ModDate :MyDate But,...
0
MMcCarthy
by: MMcCarthy | last post by:
Rather than using the Access design view change the view to SQL. I am going to attempt to outline the general syntax used for SQL queries in Access. Angle brackets <> are used in place of some...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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
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?
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...

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.