dbTalk Databases Forums  

Parameter query

comp.databases.ms-access comp.databases.ms-access


Discuss Parameter query in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Phil
 
Posts: n/a

Default Parameter query - 12-12-2010 , 11:07 AM






Here is a bit of code from the middle of a long module for creating a Mail
merge data file

If Left(strSQL, 10) = "PARAMETERS" Then
Stop ' ?????????????
End If

Set rstOutput = CurrentDb.OpenRecordset(strSQL, , dbSeeChanges)

The strSQL comes from a variely of sources such as a query, a form or
report's record source or a table . If there are no parameters, everything
works perfectly. So we must assume there is no QueryDef associared with the
strSQL string

Here is a sample of an actual strSQL string

PARAMETERS [Enter date of last New Member's Evening] DateTime;
SELECT DISTINCT QAddressLabelsFamily.*
FROM Member INNER JOIN QAddressLabelsFamily ON Member.[MemHeadOfHouseID] =
QAddressLabelsFamily.[MemHeadOfHouseID] WHERE (((Member.MemJoinDate)>[Enter
date of last New Member's Evening])) ORDER BY
QAddressLabelsFamily.MemSurName;

How do I get the "Enter parameter" box to open and pass the parameter to the
recordset?

Thanks

Phil

Reply With Quote
  #2  
Old   
David-W-Fenton
 
Posts: n/a

Default Re: Parameter query - 12-12-2010 , 05:59 PM






"Phil" <phil (AT) stantonfamily (DOT) co.uk> wrote in
news:ie2vgs$c8i$1 (AT) speranza (DOT) aioe.org:

Quote:
Here is a sample of an actual strSQL string

PARAMETERS [Enter date of last New Member's Evening] DateTime;
SELECT DISTINCT QAddressLabelsFamily.*
FROM Member INNER JOIN QAddressLabelsFamily ON
Member.[MemHeadOfHouseID] =
QAddressLabelsFamily.[MemHeadOfHouseID] WHERE
(((Member.MemJoinDate)>[Enter date of last New Member's Evening]))
ORDER BY QAddressLabelsFamily.MemSurName;

How do I get the "Enter parameter" box to open and pass the
parameter to the recordset?
If you're executing the SQL in code and it's not a saved QueryDef,
then use SQL that omits the parameter(s) and just collect the data
from the user with a form, and write your SQL with that.

Now, some will claim that opens you to SQL injection, but in an
Access app, the danger there is quite small. And you can easily
avoid that by using certain assumptions about the criteria.

If you really want to use parameters, you have to open the query
def, assign the parameter values and then execute it.

For what it's worth, I've never done that even once in my 14 years
of programming Access professionally. I just provide the WHERE
clause at runtime.

--
David W. Fenton http://www.dfenton.com/
contact via website only http://www.dfenton.com/DFA/

Reply With Quote
  #3  
Old   
Phil
 
Posts: n/a

Default Re: Parameter query - 12-13-2010 , 02:50 AM



On 12/12/2010 23:59:08, "David-W-Fenton" wrote:
Quote:
"Phil" <phil (AT) stantonfamily (DOT) co.uk> wrote in
news:ie2vgs$c8i$1 (AT) speranza (DOT) aioe.org:

Here is a sample of an actual strSQL string

PARAMETERS [Enter date of last New Member's Evening] DateTime;
SELECT DISTINCT QAddressLabelsFamily.*
FROM Member INNER JOIN QAddressLabelsFamily ON
Member.[MemHeadOfHouseID] =
QAddressLabelsFamily.[MemHeadOfHouseID] WHERE
(((Member.MemJoinDate)>[Enter date of last New Member's Evening]))
ORDER BY QAddressLabelsFamily.MemSurName;

How do I get the "Enter parameter" box to open and pass the
parameter to the recordset?

If you're executing the SQL in code and it's not a saved QueryDef,
then use SQL that omits the parameter(s) and just collect the data
from the user with a form, and write your SQL with that.

Now, some will claim that opens you to SQL injection, but in an
Access app, the danger there is quite small. And you can easily
avoid that by using certain assumptions about the criteria.

If you really want to use parameters, you have to open the query
def, assign the parameter values and then execute it.

For what it's worth, I've never done that even once in my 14 years
of programming Access professionally. I just provide the WHERE
clause at runtime.

Thanks David.

Somehow the posting you have just replied to came under the OP heading of
"Parameter box showing when it shouldn't" It was repeated as a new posting
"Passing a parameter" which has now been solved

Sorry for the confusion

Phil

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.