473,397 Members | 1,969 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,397 software developers and data experts.

Lost - Please help with a query

Hi,

I have nearly finished my database and I would like to add a query
that uses a combo box to get the results, not the usual paramater
style input. I suppose it would need a form and a query and a combo
box, but where to start !!!!!!!!

Any kind soul out there that can give me an example of where to
start..........?

Many Thanks

Joe

Apr 6 '07 #1
5 2000
On 6 Apr 2007 14:47:34 -0700, deaconj999 wrote:
Hi,

I have nearly finished my database and I would like to add a query
that uses a combo box to get the results, not the usual paramater
style input. I suppose it would need a form and a query and a combo
box, but where to start !!!!!!!!

Any kind soul out there that can give me an example of where to
start..........?

Many Thanks

Joe
Is the query to be viewed by itself, or is it used as the recordsource
for a report.
Different methods.
--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
Apr 6 '07 #2
Hi,

What you really meant to say was "use a combo-box to specify criteria"
instead of being prompted for it as per the usual (eg [Enter a nuber between
1 and 6] )parameter query, right?

My suggestion,( if this is what you want) is to design an unbound main form
to put your combo-box on, and a datasheet style subform that will be used to
display the results.

Use the combo-boxes AfterUpdate to build your SQL statement (query) in code,
and then use the resulting SQL as the RecordSource for the subform.
Here is a code sample:
=======================

Public Sub sRequerySubform()
'What I want to do here is build the RecordSource for the subform
'ON-THE-FLY...to allow for a variable WHERE statement.
'IF the user wants to view:
' 1.) ALL records
' The combo-box also has an "All" option. Instructions at
http://www.mvps.org/access/forms/frm0043.htm

' 2.) filtered by Line code (a 3-character brand abbreviation)

Dim MySQL As String
Dim RptSQL As String
Dim whr As String

Dim MyLine
MyLine = Me![cboLine]

'Build the SELECT portion of the SQL statement
MySQL = ""
MySQL = MySQL & "SELECT tblPartsInventory.* FROM tblPartsInventory "

'Build the WHERE portion
whr = "" 'initialize variable

If Not IsNull(MyLine) And MyLine <"(All)" Then
whr = whr & "(tblPartsInventory.Line = '"
whr = whr & MyLine
whr = whr & "' )"
MySQL = MySQL & "WHERE ("
MySQL = MySQL & whr
MySQL = MySQL & ") "
End If

'The report will use the same SQL except it needs this line added.
RptSQL = MySQL & "And (tblPartsInventory.Selected = True)" & ";"

MySQL = MySQL & "ORDER BY tblPartsInventory.Line,
tblPartsInventory.PartNumber "
MySQL = MySQL & ";"

'Debug.Print "MySQL: " & MySQL
'Debug.Print "-------------------------" & CR
'Debug.Print "RptSQL: " & RptSQL
Me![sbfBinLabelSelection].Form.RecordSource = MySQL

End Sub

==================

--
--
HTH,
Don
=============================
E-Mail (if you must) My*****@Telus.net

Disclaimer:
Professional PartsPerson
Amateur Database Programmer {:o)

I'm an Access97 user, so all posted code samples are also Access97- based
unless otherwise noted.

================================================== ========================
"deaconj999" <de********@btinternet.comwrote in message
news:11**********************@y66g2000hsf.googlegr oups.com...
Hi,

I have nearly finished my database and I would like to add a query
that uses a combo box to get the results, not the usual paramater
style input. I suppose it would need a form and a query and a combo
box, but where to start !!!!!!!!

Any kind soul out there that can give me an example of where to
start..........?

Many Thanks

Joe

Apr 7 '07 #3
On Apr 6, 5:47 pm, "deaconj999" <deaconj...@btinternet.comwrote:
Hi,

I have nearly finished my database and I would like to add a query
that uses a combo box to get the results, not the usual paramater
style input. I suppose it would need a form and a query and a combo
box, but where to start !!!!!!!!

Any kind soul out there that can give me an example of where to
start..........?

Many Thanks

Joe
Joe,

1. Create a query to "feed" the combo box, including only the fields
you want to appear in the combo box.

2. Create an unbound form or use an existing form, depending on from
where you want the user to conduct the search.

3. Put a combo box on your form, using your query from step 1 as the
row source. (I like to use the wizard for combo boxes. Click the
wizard button on the tool bar before you place the combo box on your
form, and then just answer the questions to set up the combo box.)
Give the combo box a name or remember the one Access gave it.

4. Decide how you want the user to initiate the search. I would
suggest a couple of buttons on the form; one thats says "Search" and
one that says "Cancel".

5. Create another query for your search results. In the criteria blank
for the field in this query that matches the combo box type: Like
"[Forms]![Name of Your Form]![Name of your combo box]". (If the field
is numeric or date/time, as opposed to text, use = instead of Like.)

6. Create macrosnfor the buttons. If you choose "Macro Names" from the
View menu, you can place both of the macros is the same macro group.
For the "Search" macro, merely use an OpenQuery command to open the
search result query. For the "Cancel" macro, use a Close command on
the search form.

7. If you would rather the user view the search results in a form or
report instead of a query, create one, using the query as the control
source.

That's the simplest way I know of to do it and it doesn't involve any
knowledge of VBA.

Good luck.

Steve

Apr 7 '07 #4
On Apr 7, 4:53 am, scart...@alltel.net wrote:
On Apr 6, 5:47 pm, "deaconj999" <deaconj...@btinternet.comwrote:
Hi,
I have nearly finished my database and I would like to add a query
that uses a combo box to get the results, not the usual paramater
style input. I suppose it would need a form and a query and a combo
box, but where to start !!!!!!!!
Any kind soul out there that can give me an example of where to
start..........?
Many Thanks
Joe

Joe,

1. Create a query to "feed" the combo box, including only the fields
you want to appear in the combo box.

2. Create an unbound form or use an existing form, depending on from
where you want the user to conduct the search.

3. Put a combo box on your form, using your query from step 1 as the
row source. (I like to use the wizard for combo boxes. Click the
wizard button on the tool bar before you place the combo box on your
form, and then just answer the questions to set up the combo box.)
Give the combo box a name or remember the one Access gave it.

4. Decide how you want the user to initiate the search. I would
suggest a couple of buttons on the form; one thats says "Search" and
one that says "Cancel".

5. Create another query for your search results. In the criteria blank
for the field in this query that matches the combo box type: Like
"[Forms]![Name of Your Form]![Name of your combo box]". (If the field
is numeric or date/time, as opposed to text, use = instead of Like.)

6. Create macrosnfor the buttons. If you choose "Macro Names" from the
View menu, you can place both of the macros is the same macro group.
For the "Search" macro, merely use an OpenQuery command to open the
search result query. For the "Cancel" macro, use a Close command on
the search form.

7. If you would rather the user view the search results in a form or
report instead of a query, create one, using the query as the control
source.

That's the simplest way I know of to do it and it doesn't involve any
knowledge of VBA.

Good luck.

Steve
Many thanks

Apr 7 '07 #5
On Apr 7, 1:47 am, "deaconj999" <deaconj...@btinternet.comwrote:
On Apr 7, 4:53 am, scart...@alltel.net wrote:


On Apr 6, 5:47 pm, "deaconj999" <deaconj...@btinternet.comwrote:
Hi,
I have nearly finished my database and I would like to add a query
that uses a combo box to get the results, not the usual paramater
style input. I suppose it would need a form and a query and a combo
box, but where to start !!!!!!!!
Any kind soul out there that can give me an example of where to
start..........?
Many Thanks
Joe
Joe,
1. Create a query to "feed" the combo box, including only the fields
you want to appear in the combo box.
2. Create an unbound form or use an existing form, depending on from
where you want the user to conduct the search.
3. Put a combo box on your form, using your query from step 1 as the
row source. (I like to use the wizard for combo boxes. Click the
wizard button on the tool bar before you place the combo box on your
form, and then just answer the questions to set up the combo box.)
Give the combo box a name or remember the one Access gave it.
4. Decide how you want the user to initiate the search. I would
suggest a couple of buttons on the form; one thats says "Search" and
one that says "Cancel".
5. Create another query for your search results. In the criteria blank
for the field in this query that matches the combo box type: Like
"[Forms]![Name of Your Form]![Name of your combo box]". (If the field
is numeric or date/time, as opposed to text, use = instead of Like.)
6. Create macrosnfor the buttons. If you choose "Macro Names" from the
View menu, you can place both of the macros is the same macro group.
For the "Search" macro, merely use an OpenQuery command to open the
search result query. For the "Cancel" macro, use a Close command on
the search form.
7. If you would rather the user view the search results in a form or
report instead of a query, create one, using the query as the control
source.
That's the simplest way I know of to do it and it doesn't involve any
knowledge of VBA.
Good luck.
Steve

Many thanks- Hide quoted text -

- Show quoted text -
I'll toss in one more approach. I'm assuming that all you need is a
different filter on the report (the usual). If so, then use the combo
box to get what it is to be reported on. You can then use the filter
on the report open code to have the report show what is desired. For
example

docmd.openreport "MyReport",,,, "Key = " & me.comboBox

I don't remember off-hand how many commas are needed here, but VBA
will show you the arguments once you start typing.

-- Larry Engles

Apr 8 '07 #6

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

Similar topics

2
by: Bartosz Wegrzyn | last post by:
Hi, I have simple web with authentication. My main page looks like this: <?php include ("nav.htm"); include ("auth.php"); $menu = $_GET;
0
by: jackson marshmallow | last post by:
I have just recreated several (large) tables in the database as InnoDB and reloaded them using my client application... These tables used to be MyISAM. I haven't tried playing with any InnoDB...
3
by: Matias Silva | last post by:
Hi Everyone, I wrote a for loop to build several select statements that are combined with a UNION. When I execute one of the queries separately, it works, but when I execute the query with a UNION...
6
by: garyusenet | last post by:
I have created a new project. and within this project as per the tutorial created an sql database. i have made a query which returns the result i need. 1. I cant SAVE THE QUERY? where on earth...
7
by: VB Programmer | last post by:
I've lost the Data Sources tab (in Whidbey). How can I make it reappear? I need to "Add New Data Source..." Thanks!
6
by: Vyoma | last post by:
This is quite a bit of problem I am facing, and I cannot point exactly where I am going wrong. I have been lurking around at several forums with regard to login and user authentication scripts and...
0
by: Bruno Barberi Gnecco | last post by:
I'm using stored procedures in a PHP site, with mysql. I'm having problems with stored procedures. Of the two I'm using, one works all the time, consistently. The other works correctly, but the...
13
by: SAL | last post by:
Okay, don't bash me to hard for my design on this app, it's my first web app and it's in production. My basic design is using Datatables created via the designer with a business logic class in...
2
by: Nightcrawler | last post by:
I have the following tables that I have dragged into a .dbml file ( have only included the keys for simplicity). Users have a one to many relationship on Items keyed on UserId = UserId. Users...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...

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.