473,770 Members | 2,153 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Databound list box populated with parameterized query?

Hello.

I am developing an Access 2000 form, and I want to populate a
databound list box using a saved query that requires parameters.
Is there any way to do this? I tried creating a DAO querydef
object and setting the parameters, and then assigned the querydef
object to the list box "rowsource" property. This did not work.

Thanks
-Mark
Feb 7 '06 #1
7 6218
> I am developing an Access 2000 form, and I want to populate a
databound list box using a saved query that requires parameters.
Is there any way to do this? I tried creating a DAO querydef
object and setting the parameters, and then assigned the querydef
object to the list box "rowsource" property. This did not work.


I use a function to pass parameters to queries most of the time. If I need
to pass a file path or some other string that may contain quotes or
potential problem characters, then I use a parameter query.

If you can get the value needed from a control, or put it in a hidden
textbox on a form, you can use this function in the query.

example:

SELECT * FROM qryMyQuery WHERE MyField_ID = QryPrm("frmMain ", "txtMyId")

Public Function QryPrm(ByVal strFrm As String, ByVal strCtl As String, _
Optional ByVal strSubFrm As String, Optional ByVal strSubFrmCtl As
String) _
As Variant
If Len(strSubFrmCt l) = 0 Then
If Len(strSubFrm) = 0 Then
QryPrm = Forms(strFrm).C ontrols(strCtl)
Else
QryPrm = Forms(strFrm).C ontrols(strCtl) .Form.Controls( strSubFrm)
End If
Else
QryPrm =
Forms(strFrm).C ontrols(strCtl) .Form.Controls( strSubFrm).Form .Controls(strSu bFrmCtl)
End If
End Function
Feb 7 '06 #2
"deko" <de**@nospam.co m> wrote:

If you can get the value needed from a control, or put it in a hidden
textbox on a form, you can use this function in the query.

example:

SELECT * FROM qryMyQuery WHERE MyField_ID = QryPrm("frmMain ", "txtMyId")


That works, thank you very much.

I find it odd that Access does not support a syntax for executing queries
with parameters,
without resorting to object references for the parameters. But as long as
there is a way to
do it, I guess I won't complain too much.

-Mark

Feb 8 '06 #3
"deko" <de**@nospam.co m> wrote:

If you can get the value needed from a control, or put it in a hidden
textbox on a form, you can use this function in the query.

example:

SELECT * FROM qryMyQuery WHERE MyField_ID = QryPrm("frmMain ", "txtMyId")


That works, thank you very much.

I find it odd that Access does not support a syntax for executing queries
with parameters,
without resorting to object references for the parameters. But as long as
there is a way to
do it, I guess I won't complain too much.

-Mark


Feb 8 '06 #4
Maybe I'm missing something here ...but

I cant see that using the function in this case is any different than
coding:

SELECT * FROM qryMyQuery WHERE MyField_ID = forms!frmMain!t xtMyId

seeing you have the form and the control hard coded as parameters in
the query anyway.

It would be nice if the form and control names could be provided at run
time but I can't see a simple way of doing this.

Mark wrote:
"deko" <de**@nospam.co m> wrote:

If you can get the value needed from a control, or put it in a hidden
textbox on a form, you can use this function in the query.

example:

SELECT * FROM qryMyQuery WHERE MyField_ID = QryPrm("frmMain ", "txtMyId")


That works, thank you very much.

I find it odd that Access does not support a syntax for executing queries
with parameters,
without resorting to object references for the parameters. But as long as
there is a way to
do it, I guess I won't complain too much.

-Mark


Feb 8 '06 #5
> I cant see that using the function in this case is any different than
coding:

SELECT * FROM qryMyQuery WHERE MyField_ID = forms!frmMain!t xtMyId


It's not. That function is just my way to get variables into queries. I
find it easy to work with, debug and troubleshoot.

There's different ways to do it - that's just my preference, most of the
time.

I also like to do this (for SELECT queries):

Dim db as DAO.Database
Dim qdfs as DAO.Querydefs
Dim qdf as DAO.Querydef
Set db = CurrentDB
Set qdfs = db.Querydefs
Set qdf = qdfs(strQryName )
strSql = "dynamicall y created statement here"
qdf.SQL = strSql

And this (for simple action queries):

db.Execute strSql, dbFailOnError

And sometimes this (for more complex action queries):

qdf.Parameters( "prmWhateve r") = "parameter"
qdf.Execute

It all depends on the situation at hand.
Feb 9 '06 #6
Thanks for that.

Your idea of using a function I think may have solved a problem for me.

I have a financial application where records may be kept for a number
of Clients (/holders/entities - call them what you like). I have forms
such as Cheque (check), Direct deposit, Payments, Bank Statement etc
which all have a BankAccount combo box.
I only want it to show bank accounts for the holder who I am working on
in the drop down list, not bank accounts for every one, so the row
source of the combo box on each form is "Select
BankAccount.Acc ountNumber, ........from BankAccount where holderId =
forms!formname! holderId. As I can only work with 1 holder at a time
regardless of which form I use the HolderId will be the same. This
means instead of having a separate query on each combo box with only
the formname different in the WHERE clause I could have a common query
if I had a common HolderId reference point. I in fact do have that. I
have a class module calle gblHolder that looks up and holds a number of
attributes about a holder. Whenever I change holders this gets
populated so I dont have to have queries to read the database for the
same holder info all the time.

I tried using gblHolder.Holde rId in the query - i.e. Select ..... from
BankAccount where holderId = gblHolder.Holde rId but this didn't work -
seems queries wont look at class modules.

But using your method I can call a function that looks up gblHolder and
returns HolderId to the query. Now I can use a generalised query in
all forms that have a BankAccount combo box instead of a slightly
different one on each form.

Thanks

Feb 9 '06 #7
> Your idea of using a function I think may have solved a problem for me.

Glad to hear it. In once scenario, similar to what you described, I have a
form with a "Transactio n Type" and a "Transactio n Account" combo box.

The Transaction Type RowSource looks like this:

SELECT tblTxType.TxTyp e_ID, tblTxType.TxTyp eName
FROM tblTxType INNER JOIN tblTxJournal ON tblTxType.TxTyp e_ID =
tblTxJournal.Tx Type_ID
WHERE tblTxJournal.En tity_ID = QryPrm("frm1", "Entity_ID" )
UNION SELECT 0, "<All Transaction Types>" FROM tblTxType
ORDER BY TxTypeName;

And the Transaction Account RowSource looks like this:

SELECT tblTxAcct.TxAcc t_ID, tblTxAcct.TxAcc tName
FROM tblTxAcct INNER JOIN tblTxJournal ON tblTxAcct.TxAcc t_ID =
tblTxJournal.Tx Acct_ID
WHERE (tblTxJournal.E ntity_ID = QryPrm("frm1", "Entity_ID" )) And
(tblTxJournal.T xType_ID = QryPrm("frm1", "cbx1TxType ") Or QryPrm("frm1",
"cbx1TxType ") = 0)
UNION SELECT 0, "<All Accounts>" FROM tblTxAcct
ORDER BY TxAcctName;

So TxTypes are filtered to only those Types containing transactions for the
current Entity, and TxAccts are filtered to only those Accounts containing
transactions, belonging to the selected Type, belonging to the current
Entity.

Feb 10 '06 #8

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

Similar topics

1
6078
by: gary b | last post by:
Hello When I use a PreparedStatement (in jdbc) with the following query: SELECT store_groups_id FROM store_groups WHERE store_groups_id IS NOT NULL AND type = ? ORDER BY group_name
8
12926
by: deko | last post by:
I'm trying to open a Recordset based on a parameterized query. I'm kind of new to parameterized queries, so I'm sure I'm missing something simple. Set qdfs = db.QueryDefs Set qdf = qdfs("qryInvoices") qdf.Parameters("prmInv") = strInvoice qdf.Parameters("prmCid") = lngCustomerID Set rst = db.OpenRecordset("qryInvoices")
11
3804
by: anony | last post by:
Hello, I can't figure out why my parameterized query from an ASP.NET page is dropping "special" characters such as accented quotes & apostrophes, the registered trademark symbol, etc. These symbols insert without problem from query analyzer, so that suggests it's something within ASP.NET. I've tried using .NET textbox web controls as well as html textareas. I have a test database set up with 4 fields: varchar, nvarchar, text, and...
9
1521
by: zacks | last post by:
I have written a serialized class that has several properties that are typed as a list of type class. When I deserialize an XML file, the list is populated just fine. But I am having trouble manually loading the class for serialization when the class has not been initialized by a deserialize. If I add three instances of a class to the list, each with different values for their properties, the XML file created by serialization has three...
9
13906
by: Jakob Lithner | last post by:
1) I have a DataGridView with edit capability. But in some columns I want to limit the input with a DropDownList. There is no inbuilt column for DropDownLists so I intended to add one myself. I thought the TemplateField would be a good candidate so I added a DropDownList in the EditItemTemplate and a Literal in the ItemTemplate, but then I was kind of lost .... It would be convenient to use the DataGridView for all other fields but maybe...
1
2878
by: IMB | last post by:
I'm using VS2005 and am working with a ASP.NET 2.0 web site and I'm coding in VB.NET. I understand that I can add an item to a databound dropdownlist and make it the default selection using the following code: MyDropDownList.Items.Insert(0, "My default item") MyDropDownList.SelectedIndex = 0 The problem that I am experiencing is *where* to put the above code! If I
0
1516
by: thebison | last post by:
Hi all, I hope someone can help with this relatively simple problem. I am building a timesheet application using ASP.NET C# with Visual Studio 2003.As it is only a protoype application, my database has been made in MSDE. My question is simple, on my Projects form I have a 'search' button, which when clicked re-binds a datagrid with a RowFilter based on a number of user-input parameters. Two of these parameters are drop-down
3
1895
by: ssims | last post by:
For some reason my databound DropDownList will not populate. I've tried a variety of things...here's the latest. - I pulled a DropDownList on to the page. - Then I pulled a SqlDataAdapter and set the select query to "SELECT * FROM Items". - I chose Generate DataSet... from the SqlDataAdapter's properties. - I set the DataSource, DataMember, DataTextField, and DataValueField properties in the Properties window. - Then I put...
8
8053
by: Roland Hall | last post by:
In Access you use "*" + + "*", + can be replaced with & Calling a parameterized query in Access requires % be used in place of *, however, all that I have read show dynamic SQL passed to Access: WHERE LIKE '" & ASPvar & "' % ORDER BY ... However, my call is similar to: conn.qMyLookup strVar, rs
0
9425
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10228
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10002
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9869
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8883
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7415
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3970
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3575
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.