473,569 Members | 2,872 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.cboRestauran t

Dim strSQL As String

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

DoCmd.OpenRepor t "rptRestaurants MultiFind", 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 2073
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.OpenRepor t. 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.t xtCuisine = """ & 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*******@veriz on.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
'strRestaura nt = Me.cboRestauran t

Dim strSQL As String

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

DoCmd.OpenRepo rt "rptRestaurants MultiFind", acViewPreview

Me.RecordSourc e = 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_Handle r:
MsgBox Err.Number & " " & Err.Description

End Sub


Nov 12 '05 #2
"amywolfie" <am*******@veri zon.net> wrote in message
news:33******** *************** ***@posting.goo gle.com...
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.cboRestauran t

Dim strSQL As String

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

DoCmd.OpenRepor t "rptRestaurants MultiFind", 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.OpenRepor t "rptRestaurants MultiFind", 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
6917
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 follows: <silcn:silcn xmlns:silcn='http://silcn.org/200309' xmlns='http://xmlprobe.com/200312'> it contains an element <report> off the root and...
9
3061
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 to appear in the report is Yes, No, or Maybe. What do I need to do to change what appears in the report/what term do I need to search out in Google?...
11
6566
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 where the job is running, the job runs sucessfully, PDF files got generated, everything is good. If I scheduled the job to run at the time that I am...
3
3410
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 working on. I am working with MS Access 2002. And I am having a problem with one of my charts. I will explain how everything is laid out then go...
2
4894
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 the error : 1. When I connecct postgresql using powerbuilder , there is message like this ... Catalog tables could not be created and are not...
12
1686
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 the type of report to generate: Select the type of report to display: <form runat="server"> <asp:DropDownList AutoPostBack="true" ID="report"...
13
12779
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 scripting language that makes writing automated tests simpler. Really, I'm looking to kind of abstract the power of the C# language into a simpler...
0
1148
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 funtionality as individual windows form application(not a MDI frame) I was able to generate the report. I feel I am facing the problem with the below...
5
4245
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 all open invoices (this works), total all invoices (this works), and have boxes at the bottom that show amounts currently due, 30 days past due, 60...
0
7703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7930
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. ...
0
8138
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7681
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...
0
7983
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...
0
6290
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...
1
5514
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...
0
5228
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...
0
3651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.