473,382 Members | 1,392 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.

Parameterised query question

Hi

I have a parameterised query for a report like this;

PARAMETERS Event_ID Short;
SELECT DISTINCTROW Events.[Event ID], ...
FROM Events
WHERE (((Events.[Event ID])=[Event_ID]));

Now I am trying to run the report while passing the parameter value like
this;

docmd.OpenReport "My Report",acViewPreview,,"[Event_ID] = 6736"

it does not work and the parameter entry dialog still appears to read a
value manually. How can I make it work via code?

Thanks

Regards
Dec 29 '06 #1
5 1495
On Fri, 29 Dec 2006 05:20:11 -0000, "John" <Jo**@nospam.infovis.co.uk>
wrote:
>Hi

I have a parameterised query for a report like this;

PARAMETERS Event_ID Short;
SELECT DISTINCTROW Events.[Event ID], ...
FROM Events
WHERE (((Events.[Event ID])=[Event_ID]));

Now I am trying to run the report while passing the parameter value like
this;

docmd.OpenReport "My Report",acViewPreview,,"[Event_ID] = 6736"

it does not work and the parameter entry dialog still appears to read a
value manually. How can I make it work via code?
You're missing the point of how parameters work, or how the OpenReport
method works. If you're using the WhereCondition argument in
OpenReport to pass a literal value, you don't NEED a parameter. You
could just base the Report directly on Events and use

docmd.OpenReport "My Report",acViewPreview,,"[Event ID] = 6736"
John W. Vinson[MVP]
Dec 29 '06 #2
Hi, John.

To add to what others have advised, if you ever need a parameter (and most of
the time you won't), you can create one in the WHERE clause, instead of
declaring the parameter with the PARAMETERS key word and selecting the data
type. Try:

SELECT DISTINCTROW Events.[Event ID], Col1, Col2
FROM Events
WHERE (((Events.[Event ID])=[Enter Event ID:]));

This will prompt the user with:

Enter Event ID:

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
http://www.Access.QBuilt.com/html/ex...ributors2.html for contact info.
"John" <Jo**@nospam.infovis.co.ukwrote in message
news:ud**************@TK2MSFTNGP02.phx.gbl...
Hi

I have a parameterised query for a report like this;

PARAMETERS Event_ID Short;
SELECT DISTINCTROW Events.[Event ID], ...
FROM Events
WHERE (((Events.[Event ID])=[Event_ID]));

Now I am trying to run the report while passing the parameter value like this;

docmd.OpenReport "My Report",acViewPreview,,"[Event_ID] = 6736"

it does not work and the parameter entry dialog still appears to read a value
manually. How can I make it work via code?

Thanks

Regards


Dec 29 '06 #3
On Fri, 29 Dec 2006 00:57:54 -0800, "'69 Camaro"
<Fo**************************@Spameater.orgZERO_SP AMwrote:
>To add to what others have advised, if you ever need a parameter (and most of
the time you won't), you can create one in the WHERE clause, instead of
declaring the parameter with the PARAMETERS key word and selecting the data
type.
That's *usually* true - but some queries are quirky. For instance a
Crosstab query requires the use of the PARAMETER declaration, and
gives a confusing error message if it's omitted.

Declaring a parameter is an extra step, but IME it never hurts to do
so.

John W. Vinson[MVP]
Dec 29 '06 #4
Hi, John.
For instance a
Crosstab query requires the use of the PARAMETER declaration, and
gives a confusing error message if it's omitted.
Excellent point.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
http://www.Access.QBuilt.com/html/ex...ributors2.html for contact info.
"John Vinson" <jvinson@STOP_SPAM.WysardOfInfo.comwrote in message
news:k0********************************@4ax.com...
On Fri, 29 Dec 2006 00:57:54 -0800, "'69 Camaro"
<Fo**************************@Spameater.orgZERO_SP AMwrote:
>>To add to what others have advised, if you ever need a parameter (and most of
the time you won't), you can create one in the WHERE clause, instead of
declaring the parameter with the PARAMETERS key word and selecting the data
type.

That's *usually* true - but some queries are quirky. For instance a
Crosstab query requires the use of the PARAMETER declaration, and
gives a confusing error message if it's omitted.

Declaring a parameter is an extra step, but IME it never hurts to do
so.

John W. Vinson[MVP]

Dec 29 '06 #5
Another option is You just need to define the parameters before you use
the report:
Public Sub DemoParameters()

Dim cmd As ADODB.Command
Dim rst As ADODB.Recordset
Dim prm As ADODB.Parameter

' Before running this procedure, open
' frmInfo and enter a value, like "Berlin",
' into the City text box, then tab off of the text box.
' You must move the focus out of the City text box in
' order for this to work.
Stop
Set cmd = New ADODB.Command
Set cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandText = "qryCustCity"
' If you use adCmdStoredProc,
' this won't work
cmd.CommandType = adCmdTable

' This next statement is actually optional
' If you leave it out, ADO does it anyway.
cmd.Parameters.Refresh
' Loop through the parameters
For Each prm In cmd.Parameters
prm.Value = Eval(prm.Name)
Next prm

' And populate the recordset
Set rst = cmd.Execute
Do Until rst.EOF
Debug.Print rst.Fields(0).Value
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
Set cmd = Nothing
End Sub
then run report
docmd.runreport
this is an excerpt from access 2002 desktop developers handbook i use I
cut out the part i need where it steps through the parameters and put
the query name in the commandtext var. it will step through the
parameters in the query and then when you run the report it will be
full.
Lewie

'69 Camaro wrote:
Hi, John.
For instance a
Crosstab query requires the use of the PARAMETER declaration, and
gives a confusing error message if it's omitted.

Excellent point.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
http://www.Access.QBuilt.com/html/ex...ributors2.html for contact info.
"John Vinson" <jvinson@STOP_SPAM.WysardOfInfo.comwrote in message
news:k0********************************@4ax.com...
On Fri, 29 Dec 2006 00:57:54 -0800, "'69 Camaro"
<Fo**************************@Spameater.orgZERO_SP AMwrote:
>To add to what others have advised, if you ever need a parameter (and most of
the time you won't), you can create one in the WHERE clause, instead of
declaring the parameter with the PARAMETERS key word and selecting the data
type.
That's *usually* true - but some queries are quirky. For instance a
Crosstab query requires the use of the PARAMETER declaration, and
gives a confusing error message if it's omitted.

Declaring a parameter is an extra step, but IME it never hurts to do
so.

John W. Vinson[MVP]
Dec 29 '06 #6

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

Similar topics

1
by: Jakob | last post by:
Hey... Why do I sometimes experience low performance when I use a parameter instead of an exact value? For example the following performs very bad:
9
by: Phil Sowden | last post by:
I'd really appreciate your help creating a parameterised view in SQL Server, which I can then invoke from VB5. I'm using DAO and ODBC to connect to SQL Server 2000. I can open Tables and Views,...
5
by: u7djo | last post by:
I've built a query in Access and added a parameter to it called . I'm trying to load the recordset by using an ADO command and attaching a parameter to it but I keep getting an error message when...
5
by: Tim Marsden | last post by:
Hello, I am building a parameterised query in vb.net for execution against a SQL server database. I am using a OLEDB command and OLEDB parameters. If one of the parameters is a date I sometimes...
7
by: John | last post by:
Hi I have the following sql for my dataadapter; SELECT ID, Company, Status FROM Companies WHERE Status = @Status I fill the dataadapter as...
0
by: ken | last post by:
Hi, I connected Access 2003 to SQL express 2005. My question is in access if I have a query, I can put in the criteria a function to return some kind of criteria statement. I can also redefine the...
2
by: B.r.K.o.N.j.A | last post by:
I'm using mysql 4.1 and php5.0.4. Since (AFAIK) this version of mysql supports parameterised queries, is there a way to accomplish that using mysql_... functions (looks like mysql client library is...
1
by: DebGuria | last post by:
I have written a managed C++ dll. I have to use that dll from C#, VB .NET and VB. It has got a parameterised propetyfor the very specific requirement. For example get_Pie(float f). When I am...
0
by: John | last post by:
Hi When using sql server, I can use a sql like below in my data adapter to send the sql a parameter value; SELECT <field list> FROM <table> WHERE Fieldx = @Para1 My...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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: 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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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...

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.