A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Using a query with a replaceable parameter as the source of a control



 
 
Thread Tools Display Modes
  #1  
Old May 30th, 2004, 02:25 AM
Hoo
external usenet poster
 
Posts: n/a
Default Using a query with a replaceable parameter as the source of a control

I'm stuck, trying to base the contents of a listbox upon a query with a
variable parameter. The trouble lies in the fact that if I set the listbox
control to use the query as its rowsource, an input box pops up, asking the
user for the event id. If I leave the row source empty, I can't seem to
stuff the desired value into the parameter and execute the query with the
desired value.


Here's the query as it is saved in Access XP:

SELECT tStdnts.nStudentNum, tStdnts.stFirstName & ' ' & tStdnts.stLastName
AS stName, tBelts.stBeltLevel
FROM tblStudentInfo tStdnts , tblBeltLevels tBelts
WHERE tStdnts.nStudentNum Not In (
SELECT DISTINCT nStudentId
FROM tblTestCandidates
WHERE nEventId =[pqryNotTesting-EventId?] )
AND tStdnts.nActiveStatus=1
AND tBelts.nBeltId=tStdnts.nBeltId
ORDER BY tStdnts.nStudentGroup, tStdnts.nBeltId, tStdnts.stLastName,
tStdnts.stFirstName;


Here's the open sub of the form with the listbox. Inspection of the
qryNotTesting object in the debugger indicates that the value changes from
0 to 8 as of the last line, but how can I execute the modified query and
drop the results into the listbox?

Private Sub Form_Open(Cancel As Integer)

Dim nEvent As Long
Dim strSQL as string

'Get list information
Set dbStudents = CurrentDb
Set qryNotTesting = dbStudents.QueryDefs("pqryNotTesting")


strSQL = qryNotTesting.SQL
Debug.Print strSQL 'Shows access query including replaceable parameter

qryNotTesting.Parameters(0).Value = 8

End Sub


Thanks for any suggestions, including completely abandoning this attempt
and using a different technique.

--tdm




----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! 100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
  #2  
Old May 30th, 2004, 07:07 AM
tina
external usenet poster
 
Posts: n/a
Default Using a query with a replaceable parameter as the source of a control

WHERE tStdnts.nStudentNum Not In (
SELECT DISTINCT nStudentId
FROM tblTestCandidates
WHERE nEventId =[pqryNotTesting-EventId?] )


you've included a parameter in your subquery. if you don't want the
parameter box to pop up, you'll have to get the value from somewhere else -
such as a control on your open form.

hth


"Hoo" wrote in message
...
I'm stuck, trying to base the contents of a listbox upon a query with a
variable parameter. The trouble lies in the fact that if I set the

listbox
control to use the query as its rowsource, an input box pops up, asking

the
user for the event id. If I leave the row source empty, I can't seem to
stuff the desired value into the parameter and execute the query with the
desired value.


Here's the query as it is saved in Access XP:

SELECT tStdnts.nStudentNum, tStdnts.stFirstName & ' ' & tStdnts.stLastName
AS stName, tBelts.stBeltLevel
FROM tblStudentInfo tStdnts , tblBeltLevels tBelts
WHERE tStdnts.nStudentNum Not In (
SELECT DISTINCT nStudentId
FROM tblTestCandidates
WHERE nEventId =[pqryNotTesting-EventId?] )
AND tStdnts.nActiveStatus=1
AND tBelts.nBeltId=tStdnts.nBeltId
ORDER BY tStdnts.nStudentGroup, tStdnts.nBeltId, tStdnts.stLastName,
tStdnts.stFirstName;


Here's the open sub of the form with the listbox. Inspection of the
qryNotTesting object in the debugger indicates that the value changes from
0 to 8 as of the last line, but how can I execute the modified query and
drop the results into the listbox?

Private Sub Form_Open(Cancel As Integer)

Dim nEvent As Long
Dim strSQL as string

'Get list information
Set dbStudents = CurrentDb
Set qryNotTesting = dbStudents.QueryDefs("pqryNotTesting")


strSQL = qryNotTesting.SQL
Debug.Print strSQL 'Shows access query including replaceable

parameter

qryNotTesting.Parameters(0).Value = 8

End Sub


Thanks for any suggestions, including completely abandoning this attempt
and using a different technique.

--tdm




----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet

News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! 100,000

Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption

=---


 




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 Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 10:11 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.