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

QBF search criteria to report

I have a QBF form/query and a report from the QBF that shows the
results of the QBF. I would like to show the criteria on the report
that was used in the QBF to get the info on report. I can't find how
to do this except to show the "hard for users to understand" SQL WHERE
statement. Anyone have a better way?

Aug 17 '06 #1
2 4202
There are a couple of different ways that QBF forms typically work:
a) The query contains criteria such as:
[Forms].[Form1].[Text0]
b) You leave the criteria out of the query, and build a Filter string to
apply to your form (and the WhereCondition of OpenReport.)

If you use (b), you can build another string at the same time, which is a
description of the filter in plain English. You can then pass this
description to the report, and display it there.

If you would like an example of how to make a form using (b), see:
Search form - Handle many optional criteria
at:
http://allenbrowne.com/ser-62.html

In Access 2002 and later, you can pass the description in the OpenArgs of
the report. In older versions, we use a public string variable to hold the
description, and then use the report's Open event to read and clear the
string and display it on the report.

The code below illustrates how to do this in Access 2000 or later. Use the
custom function OpenTheReport() instead of DoCmd.OpenReport. Advantages:
- Defaults to Preview.
- The broken Filter argument of OpenReport is gone.
- The code that calls it does not need to handle error 2501 if the report is
cancelled.
- Still lets you know if the report was opened, i.e. check the return value.

The code goes in a standard module:

Option Explicit
Public gstrTitleInHeader As String

Public Function OpenTheReport(strDoc As String, _
Optional lngMode As AcView = acViewPreview, _
Optional strWhere As String, _
Optional strDescrip As String) As Boolean
On Error GoTo Err_OpenTheReport
'Purpose: Wrapper for OpenReport that closes report if already open.
'Return: True if the report was opened.
'Usage: Called from Form_frmReport.PrintIt()
'Arguments: strDoc = name of report.
' lngMode = acViewNormal or acViewPreview.
' strWhere = the WhereCondition to apply.
' strDescrip = description of the WhereCondition to use in
the header of the report. See TitleInHeader().

If CurrentProject.AllReports(strDoc.).IsLoaded Then
DoCmd.Close acReport, strDoc
End If

gstrTitleInHeader = strDescrip

DoCmd.OpenReport strDoc, lngMode, , strWhere
OpenTheReport = True

Exit_OpenTheReport:
Exit Function

Err_OpenTheReport:
MsgBox "Error " & Err.Number & ": " & Err.Description, "OpenTheReport()"
Resume Exit_OpenTheReport
End Function

Public Function TitleInHeader(rpt As Report) As Boolean
On Error GoTo Err_TitleInHeader
'Purpose: Read the caption from Forms.frmReport.lblTitle into
' this report's txtWhereDescrip.
'Usage: In ReportHeader's OnFormat property:
' =TitleInHeader([Report]
'Note: Report header must have text box named txtWhereDescrip.
' Can be set before calling the OpenReport action.
Dim strName As String

strName = rpt.Name

If Len(gstrTitleInHeader) 0& Then
rpt.txtWhereDescrip = gstrTitleInHeader
End If
'Reset the string.
gstrTitleInHeader = vbNullString

TitleInHeader = True

Exit_TitleInHeader:
Exit Function

Err_TitleInHeader:
MsgBox "Error " & Err.Number & ": " & Err.Description
Resume Exit_TitleInHeader
End Function

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"rinmanb70" <em**********@gmail.comwrote in message
news:11*********************@m73g2000cwd.googlegro ups.com...
>I have a QBF form/query and a report from the QBF that shows the
results of the QBF. I would like to show the criteria on the report
that was used in the QBF to get the info on report. I can't find how
to do this except to show the "hard for users to understand" SQL WHERE
statement. Anyone have a better way?

Aug 17 '06 #2
Thank you very much Allen,
It works great now.

Aug 26 '06 #3

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

Similar topics

1
by: N. Graves | last post by:
Hi, I want to have a Search Dialog box that has several text box and fields to build a search and display the results in a form. I can do everything that I need to if I us a report but I would...
4
by: Jan | last post by:
I am having problems trying to print a report based on a form. This is a search form only, no data input. There is a query that the form looks at, but then there are numerous comboxes that you...
3
by: pelcovits | last post by:
I am trying to set up an unbound form to enter report criteria. I've followed the MS Office Assistance document: "Create a form to enter report criteria" which describes how to enter data (such...
8
by: Steph | last post by:
Hi. I'm very new to MS Access and have been presented with an Access database of contacts by my employer. I am trying to redesign the main form of the database so that a button entitled...
2
by: angie | last post by:
I need to figure out how to create a user interface to search a query, but here's the bad part...I need to account for criteria on at least 7 of the fields. Here's what I'm thinking I need to do:...
1
by: Reef81 | last post by:
Does anyone know a way to have the search parameters displayed in the query or report? For example, if I set up a parameter to search all entries in my table, is there a way to have the search...
1
by: kaosx5 | last post by:
I am running Access 2003. I would like to be able to search the criteria section in an Access query to see if it populated with anything. I have a report database that has a list box and some...
1
by: billa856 | last post by:
Hi, My project is in MS Access. In that I have one Form(Search) which I am using for Search data in my Table(PRODUCTION). Now in this form I have one Combobox(PalletNo) and one button(Search)...
11
by: woodey2002 | last post by:
This problem is driving me crazy. Hello there, i am trying to create a search form for records in my access database. The search form will contain text boxes and a multi select list box. The user...
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
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
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,...
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
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
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
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.