473,769 Members | 2,376 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Access 2000: how to create a query based on a form parameter -- Please HELP!!

I would like to create a query where one of the columns of the queries
comes from a combo list box on a form.
For example, if my table has the following fields:
id
name
interest1
interest2
interest3

my combo box would be a dropdown containing these choices:
interest1
interest2
interest3

when the user selects one these in the combo box, then the following
query executes:

select id, name, [interestselecte dfrombox]
from mytable
where blah = blah

ex: they select interest3 from the combo box, then the query that
runs is:
select id, name, interest3
from mytable
where blah = blah

i've tried variants on this, but none of them have worked so far. i
need some help!!!!! if anyone could show me some specific syntax
examples, that would be great.
Nov 13 '05 #1
6 2778
Seems like you should create a table for different type of "interests"

Create a subform [b] of the query you want, and place it on main form
[A]. For subform [b], Record Source click the query builder and drag
down the columns you want for your query. For column "interest" the
criteria should be [Forms]![A]![interestselecte dfrombox]

For your comboBox, [interestselecte dfrombox], make it unbound, the
AfterUpdate event should have the following:
[Forms]![A]![interestselecte dfrombox].Requery
sa***@case.edu (sheree) wrote in message news:<f8******* *************** ***@posting.goo gle.com>...
I would like to create a query where one of the columns of the queries
comes from a combo list box on a form.
For example, if my table has the following fields:
id
name
interest1
interest2
interest3

my combo box would be a dropdown containing these choices:
interest1
interest2
interest3

when the user selects one these in the combo box, then the following
query executes:

select id, name, [interestselecte dfrombox]
from mytable
where blah = blah

ex: they select interest3 from the combo box, then the query that
runs is:
select id, name, interest3
from mytable
where blah = blah

i've tried variants on this, but none of them have worked so far. i
need some help!!!!! if anyone could show me some specific syntax
examples, that would be great.

Nov 13 '05 #2
sa***@case.edu (sheree) wrote in message news:<f8******* *************** ***@posting.goo gle.com>...
I would like to create a query where one of the columns of the queries
comes from a combo list box on a form.
For example, if my table has the following fields:
id
name
interest1
interest2
interest3

my combo box would be a dropdown containing these choices:
interest1
interest2
interest3

when the user selects one these in the combo box, then the following
query executes:

select id, name, [interestselecte dfrombox]
from mytable
where blah = blah

ex: they select interest3 from the combo box, then the query that
runs is:
select id, name, interest3
from mytable
where blah = blah

i've tried variants on this, but none of them have worked so far. i
need some help!!!!! if anyone could show me some specific syntax
examples, that would be great.


I'll hazard a guess. If you mean you want to show the id, name, and
"interest selected" from a table, then it's:

SELECT id, name, interest
FROM mytable
WHERE interest = Forms![MyOpenForm]![cboInterest];

where cboInterest is the name of the combobox control on your form...
or is that not what you meant?
Nov 13 '05 #3
The values in the combobox are actually FIELD NAMES -- not data for a
given field. So, in your code example, I really would want something
like:
SELECT id, name, Forms![MyOpenForm]![cboInterest]
FROM mytable;
But I can't seem to get this to work. Do you think it's not possible
to use a parameter for one of the select field names?

Thanks for your help!

pi********@hotm ail.com (Pieter Linden) wrote in message news:<bf******* *************** ****@posting.go ogle.com>...
sa***@case.edu (sheree) wrote in message news:<f8******* *************** ***@posting.goo gle.com>...
I would like to create a query where one of the columns of the queries
comes from a combo list box on a form.
For example, if my table has the following fields:
id
name
interest1
interest2
interest3

my combo box would be a dropdown containing these choices:
interest1
interest2
interest3

when the user selects one these in the combo box, then the following
query executes:

select id, name, [interestselecte dfrombox]
from mytable
where blah = blah

ex: they select interest3 from the combo box, then the query that
runs is:
select id, name, interest3
from mytable
where blah = blah

i've tried variants on this, but none of them have worked so far. i
need some help!!!!! if anyone could show me some specific syntax
examples, that would be great.


I'll hazard a guess. If you mean you want to show the id, name, and
"interest selected" from a table, then it's:

SELECT id, name, interest
FROM mytable
WHERE interest = Forms![MyOpenForm]![cboInterest];

where cboInterest is the name of the combobox control on your form...
or is that not what you meant?

Nov 13 '05 #4
it is possible

in the comboboxes after_update handler you have to build the query as a
string and assigne it to the form's recordsource, like this

assuming that cboInterest is a control on the form MyOpenForm, you would
write:

Private Sub cboInterest_Aft erUpdate()
with me
.form.RecordSou rce = "SELECT id, name, " & .cboInterest.va lue & "
FROM mytable"
end with
End Sub

you might alternatively consider keeping the form's record source constant
and instead hide columns (if you are displaying results in datasheet mode)
that you don't want to show, something like this:

Private Sub cboInterest_Aft erUpdate()
dim ctl as variant
with me
for each ctl in array(.ctl1, .ctl1, .ctl3 ....) 'list all your
interest controls here
ctl.controlhidd en = ctl.name = .cboInterest.va lue
next
end with
End Sub
However, I agree with the other posters that your model is probably wrong
and that you really want to normalize the interests into another table.

Regards,

--
Malcolm Cook - me*@stowers-institute.org
Database Applications Manager - Bioinformatics
Stowers Institute for Medical Research - Kansas City, MO USA

"sheree" <sa***@case.edu > wrote in message
news:f8******** *************** **@posting.goog le.com...
The values in the combobox are actually FIELD NAMES -- not data for a
given field. So, in your code example, I really would want something
like:
SELECT id, name, Forms![MyOpenForm]![cboInterest]
FROM mytable;
But I can't seem to get this to work. Do you think it's not possible
to use a parameter for one of the select field names?

Thanks for your help!

pi********@hotm ail.com (Pieter Linden) wrote in message

news:<bf******* *************** ****@posting.go ogle.com>...
sa***@case.edu (sheree) wrote in message news:<f8******* *************** ***@posting.goo gle.com>...
I would like to create a query where one of the columns of the queries
comes from a combo list box on a form.
For example, if my table has the following fields:
id
name
interest1
interest2
interest3

my combo box would be a dropdown containing these choices:
interest1
interest2
interest3

when the user selects one these in the combo box, then the following
query executes:

select id, name, [interestselecte dfrombox]
from mytable
where blah = blah

ex: they select interest3 from the combo box, then the query that
runs is:
select id, name, interest3
from mytable
where blah = blah

i've tried variants on this, but none of them have worked so far. i
need some help!!!!! if anyone could show me some specific syntax
examples, that would be great.


I'll hazard a guess. If you mean you want to show the id, name, and
"interest selected" from a table, then it's:

SELECT id, name, interest
FROM mytable
WHERE interest = Forms![MyOpenForm]![cboInterest];

where cboInterest is the name of the combobox control on your form...
or is that not what you meant?

Nov 13 '05 #5
Hi Sheree,

Try the code below...

My (pre-existing form) contains 3 listboxes and a command button, based (for
the most part) on the instructions in this KB article:
http://support.microsoft.com/default...b;en-us;124344

lstObjectTypes
lstObjectNames
lstFieldNames
cmdOpenQuery

This approach is optional ...
probably all that you really need is "lstFieldNames" , which is a
multi-select listbox containing the table's field names,
and the command button named "cmdOpenQue ry".

The " lstFieldNames_A fterUpdate()" event builds a query named "qryTemp",
and "cmdOpenQuery_C lick()" opens the query in datasheet view.

*************** *************** *************
Private Sub lstFieldNames_A fterUpdate()
'Requires: IsTableQuery() function
'http://support.microso ft.com/default.aspx?sc id=kb;en-us;113549

'Optional: How to Fill a List Box with Database Object Names
'http://support.microso ft.com/default.aspx?sc id=kb;en-us;124344

Dim MyDB As DAO.Database
Set MyDB = CurrentDb
Dim qdfTemp As QueryDef

Dim ctl As Control
Set ctl = Me.lstFieldName s

Dim MyTable As String
MyTable = Me.lstObjectNam es
'This is the optional listbox containing table names.
'You could just use your table name directly

Dim varItm As Variant
Dim strSelected As String
Dim Msg As String
Dim MySQL As String

Dim CR As String
CR = vbCrLf

If IsTableQuery("" , "qryTemp") Then
MyDB.QueryDefs. Delete ("qryTemp")
End If

For Each varItm In ctl.ItemsSelect ed

If Len(strSelected ) > 0 Then
strSelected = strSelected & ", " & ctl.ItemData(va rItm)
Else
strSelected = ctl.ItemData(va rItm)
End If

Next varItm

MySQL = ""
MySQL = MySQL & "SELECT "
MySQL = MySQL & strSelected
MySQL = MySQL & " FROM "
MySQL = MySQL & MyTable
MySQL = MySQL & "; "

Set qdfTemp = MyDB.CreateQuer yDef("qryTemp", MySQL)

Set ctl = Nothing
Set MyDB = Nothing
Set qdfTemp = Nothing

End Sub

Private Sub cmdOpenQuery_Cl ick()
DoCmd.OpenQuery ("qryTemp")
End Sub
*************** *************** *************
HTH,
Don
=============== =============== ==========

"sheree" <sa***@case.edu > wrote in message
news:f8******** *************** **@posting.goog le.com...
I would like to create a query where one of the columns of the queries
comes from a combo list box on a form.
For example, if my table has the following fields:
id
name
interest1
interest2
interest3

my combo box would be a dropdown containing these choices:
interest1
interest2
interest3

when the user selects one these in the combo box, then the following
query executes:

select id, name, [interestselecte dfrombox]
from mytable
where blah = blah

ex: they select interest3 from the combo box, then the query that
runs is:
select id, name, interest3
from mytable
where blah = blah

i've tried variants on this, but none of them have worked so far. i
need some help!!!!! if anyone could show me some specific syntax
examples, that would be great.

Nov 13 '05 #6
Thanks to everyone for all your suggestions! You've been extremely
helpful. It's true that my table design is a bad one & I'm now in the
middle of going back through and normalizing things (what I should have
done way back when, but was in a rush). This problem I'm having now
just highlights how important it is to normalize. Thanks again.

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #7

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

Similar topics

2
1524
by: Jim G | last post by:
I have two tables: TestA and TestB. Both tables have 3 fields: ID, Name, and RunDate. I need to create a query which will join the two tables first on Name but then I need to match up the RunDates even though the RunDates won't be the same. CREATE TABLE TestA (ID INT IDENTITY, Name VARCHAR(255), RunDate DATETIME) CREATE TABLE TestB (ID INT IDENTITY, Name VARCHAR(255), RunDate DATETIME)
0
3959
by: s_gregory | last post by:
The mdb is considerable size 70 +- mb. A complex union query was working well, but when an additional union select... was added into the query, selecting identical fields from a different source, it began to have problems. Failure was observed only in a few PC's at first. For example, in an NT 4.0 SP6 PC, it continued to work OK. But in my Win 2k laptop, it failed. As the union query was gradually simiplified in testing, the failure...
0
1803
by: Jonathan Fisher | last post by:
What¹s the appropriate way to create records in related, subsidiary tables when a record is created in a main table? I¹m using Access 2000, and I have a main table called tblProject, and a few other tables in one-to-one relationships with it (on the field ProjectKey), called tblProjectAccounting, tblProjectSales, etc. (I separated them to get around the limit of 255 fields, and to make record-locking more flexible.) My first thought...
0
1584
by: Josh C. | last post by:
Hello everyone. I'm a bit of an Access newbie, so please bear with me. Please go to http://www.dumoti.com/access/ to view the database - 536kb. I'll go straight into examples: In the form NIGO_ITEM, you'll notice a subform to the NIGO_REASONS table. It won't let any data be entered into this subform and it gives the error: You cannot add or change a record because a related record is required in table CUSTOMER_TABLE. (Error 3201) This...
1
2275
by: Tiga | last post by:
Surely this was possible in Access 97. Has it gone or am I just not seeing the wood from the trees. Any help Grateful. Regards
6
2100
by: bobdydd | last post by:
Access 2000 Windows XP Hi Everybody I have got a weird one here. I have a large form frmTransactions based on a single table tblTransactions. There are a lot of fields on the form but everything works OK. That is
0
1359
by: breakerman | last post by:
I have 4 inch high sprocket feed forms, for which I've defined a custom form in the Windows XP Print Server. My OKI Microline 320 has this fancy forms tear-off mode that only activates when it sees a form feed in the output. The problem is that Access appears to be outputting line spacing vertical movement to get to the next form instead of a form feed character. I've tried Force New Page in the Detail section and inserting a Page Break...
7
2276
by: J-P-W | last post by:
Hi, in the past I've spent ages writing VB routines to get around this problem, is there a simple way? I have three tables for a membership system: tblMembership - MembershipNumber; Names etc tblMembershipSubsHeader - "AmountDue" ; whether the pay by standing order and so on tblMembershipSubs - PaymentYear ; DatePaid; AmountPaid
13
2114
by: Ulv | last post by:
I have a table (TblItems) with fields Lenght, Width and Height as decimalfields. I also have the fields Desc, a text field. In a form I have created this line of code after updating: Desc = Lenght & " x " & Width & " x " & Height If the values is 100, 100, 100 the result is 100 x 7920 x 100. No matter what value I put into the width field It comes out with the same 7920. Why??
5
10280
by: Ferasse | last post by:
Hi, I'm an occasional Ms-Access developer, so there is still a lot of stuff that I don't get... Right now, I'm working on a database that stores contractual information. One of the form that I created is based on a query that links several tables. When I try to insert a record in this query-based form, I can only update the fields that are used to build relations with other tables.
0
9423
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
10210
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
9990
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
8869
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...
0
6672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5298
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5446
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3956
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
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.