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

Using a SQL Statement To Generate A Report

Hi All:

I would like to run a report based on criteria from 3 unbound combo
boxes located on a parameter form (combo boxes are: cboCuisine,
cboLocation, and cboRestaurant)

The present code for the FIND button (using just cboCuisine for
testing) is:

Private Sub Command13_Click()

On Error GoTo Error_Handler:

Dim strCuisine As String
strCuisine = Me.cboCuisine

'Dim strLocation As String
'strLocation = Me.cboLocation

'Dim strRestaurant As String
'strRestaurant = Me.cboRestaurant

Dim strSQL As String

strSQL = "SELECT tblkpCuisine.* FROM tblkpCuisine " _
& "WHERE tblkpCuisine.txtCuisine = strCuisine"

DoCmd.OpenReport "rptRestaurantsMultiFind", acViewPreview

Me.RecordSource = strSQL

Me.Requery
====

Of course, this isn't working, and the report comes up with all
records found.
The report itself is based on a query involving several related
tables.

What is the best way to accomplish the above: i.e., have the user
enter values in the three unbound combo boxes on a parameter form and
then use this criteria to run the report?

Thanks!
amy
====

Exit Sub

Error_Handler:
MsgBox Err.Number & " " & Err.Description

End Sub
Nov 12 '05 #1
3 2064
First, let's correct a misconception you seem to have about the Me keyword.
"Me" always refers to the class/instance in which Me was invoked. In this
case, it's the Form module, so Me refers to the form the button is on and has
nothing whatsoever to do with the report.

Now, the easiest way to do what you want is to simply base the report on the
tblkpCuisine table, and pass the Where expression (not including the word
"Where") to the WhereCondition argument passed to DoCmd.OpenReport. This will
filter the report's output using the expression you passed.

Oh, here's another issue. You put the variable name into the Where
expression, but the SQL that's going to execute cannot see the variable inside
the function, only code withing the function can. What you need to put into
the string is an expression of the value that was in the variable (e.g.
"tblkpCuisine.txtCuisine = """ & strCuisine & """"". This assumes that
strCuisine holds a string, and there can be no quote marks in the string.

Here's a couple of more notes.

You should not use special notation such as txt for the data types of fields
in tables as it will just make your system harder to maintain.

You should not be using text for lookup values such as Cuisine at all.
Instead, your lookup table should have an Autonumber key, and you should
reference this key from the other tables. This creates a better normalized
database such that a Cuisine name is only stored in one place, and it
eliminates things like thw quote mark issue I mentioned above.

I recommend that you read or at least skim a book on Access application
development and one on relational database design before you try to go much
farther, or you're going to make some messes that will be hard to untangle
later.

On 26 Jan 2004 14:13:37 -0800, am*******@verizon.net (amywolfie) wrote:
Hi All:

I would like to run a report based on criteria from 3 unbound combo
boxes located on a parameter form (combo boxes are: cboCuisine,
cboLocation, and cboRestaurant)

The present code for the FIND button (using just cboCuisine for
testing) is:

Private Sub Command13_Click()

On Error GoTo Error_Handler:

Dim strCuisine As String
strCuisine = Me.cboCuisine

'Dim strLocation As String
'strLocation = Me.cboLocation

'Dim strRestaurant As String
'strRestaurant = Me.cboRestaurant

Dim strSQL As String

strSQL = "SELECT tblkpCuisine.* FROM tblkpCuisine " _
& "WHERE tblkpCuisine.txtCuisine = strCuisine"

DoCmd.OpenReport "rptRestaurantsMultiFind", acViewPreview

Me.RecordSource = strSQL

Me.Requery
====

Of course, this isn't working, and the report comes up with all
records found.
The report itself is based on a query involving several related
tables.

What is the best way to accomplish the above: i.e., have the user
enter values in the three unbound combo boxes on a parameter form and
then use this criteria to run the report?

Thanks!
amy
====

Exit Sub

Error_Handler:
MsgBox Err.Number & " " & Err.Description

End Sub


Nov 12 '05 #2
"amywolfie" <am*******@verizon.net> wrote in message
news:33**************************@posting.google.c om...
Hi All:

I would like to run a report based on criteria from 3 unbound combo
boxes located on a parameter form (combo boxes are: cboCuisine,
cboLocation, and cboRestaurant)

The present code for the FIND button (using just cboCuisine for
testing) is:

Private Sub Command13_Click()

On Error GoTo Error_Handler:

Dim strCuisine As String
strCuisine = Me.cboCuisine

'Dim strLocation As String
'strLocation = Me.cboLocation

'Dim strRestaurant As String
'strRestaurant = Me.cboRestaurant

Dim strSQL As String

strSQL = "SELECT tblkpCuisine.* FROM tblkpCuisine " _
& "WHERE tblkpCuisine.txtCuisine = strCuisine"

DoCmd.OpenReport "rptRestaurantsMultiFind", acViewPreview

Me.RecordSource = strSQL

Me.Requery
====

Of course, this isn't working, and the report comes up with all
records found.
The report itself is based on a query involving several related
tables.

What is the best way to accomplish the above: i.e., have the user
enter values in the three unbound combo boxes on a parameter form and
then use this criteria to run the report?

Thanks!
amy
====

Exit Sub

Error_Handler:
MsgBox Err.Number & " " & Err.Description

End Sub

If you look in the help file under the OpenReport method, you will see there
is an optional parameter - WhereCondition. This is a string expression
that's a valid SQL WHERE clause without the word WHERE.
You can loop through your controls to build up various AND clauses noting if
the criteria is a text or number and adding quotes accordingly. The basic
idea is this:

strWhere = "[MyNumber] = " & Me.cboCombo
strWhere = strWhere & " AND [MyText]=""" & Me.txtText & """"

DoCmd.OpenReport "rptRestaurantsMultiFind", acViewPreview, , strWhere

Does that get you started?

Fletcher
Nov 12 '05 #3

Thanks very much, Fletcher! I did note the WHERE property of Open
Report, but I wasn't sure about the syntax.

I am making the transition from FileMaker Pro development to Access, so
it's the new syntax that's tripping me up.

Thanks again for the helpful advice and the civility of your reply.

Amy
==
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #4

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

Similar topics

2
by: PeterW | last post by:
I have an xml file from which I want to generate an xsd schema and at a later stage a cs class. The xml file has a mix of defined namespaces and also an empty namespace. These are defined as...
9
by: Colin McGuire | last post by:
Hi, I have an report in Microsoft Access and it displays everything in the table. One column called "DECISION" in the table has either 1,2, or 3 in it. On my report it displays 1, 2, or 3. I want...
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
3
by: StBond | last post by:
Hi everyone, I am new to Access and Visual Basic so things my be getting across a bit cloudy. I only started using VB for one week. I am having a little problem with the database that I am...
2
by: agus liem | last post by:
Hai.. I introduce myself, my name : Agus, from Indonesia. Im develop application using POwerbuilder 7 and postgresql 7.3. I have serveral error, and cannot solve yet. Anybody help me? This is...
12
by: Brad Baker | last post by:
I am trying to write a simple ASP.net/C# page which allows users to select some values and produce a report based on a SQL query. I have a self posting dropdown form which allows users to select...
13
by: jkimbler | last post by:
As part of our QA of hardware and firmware for the company I work for, we need to automate some testing of devices and firmware. Since not everybody here knows C#, I'm looking to create a new...
0
by: Raja yashwanth Reddy Gunda | last post by:
Hi I couldn't generate any report.My application is developed using .Net(MDI Frame application-windows forms) and I am trying to generate the report but couldn't succeed.If I do the same...
5
by: msrobotto | last post by:
Past Due Boxes: 30/60/90/etc Hi! I am working on creating an Accounts Receivable database, and I want to be able to automatically generate statements for my customers. The statements need to list...
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
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,...
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...
0
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,...

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.