SELECT ra_report.CCENTER,
FROM ra_report
WHERE (((ra_report.CCENTER) Like "*" & [forms]![Search Cost
Center]![Text30] & "*" Or (ra_report.CCENTER) Like "*" &
[forms]![Search Cost Center]![Text31] & "*" Or (ra_report.CCENTER) Like
"*" & [forms]![Search Cost Center]![Text32] & "*" Or
(ra_report.CCENTER) Like "*" & [forms]![Search Cost Center]![Text33] &
"*" Or (ra_report.CCENTER) Like "*" & [forms]![Search Cost
Center]![Text34] & "*" Or (ra_report.CCENTER) Like "*" &
[forms]![Search Cost Center]![Text35] & "*" Or (ra_report.CCENTER) Like
"*" & [forms]![Search Cost Center]![Text36] & "*" Or
(ra_report.CCENTER) Like "*" & [forms]![Search Cost Center]![Text37] &
"*"));
This works great, except when one of the textboxes is empty. How would
I code the following pseudo-code:
If textbox is not null, then use criteria OR If textbox is not null,
then use criteria, etc 4 2075
"Drum2001" <dr******@gmail.com> wrote in message
news:11**********************@j33g2000cwa.googlegr oups.com... SELECT ra_report.CCENTER,
FROM ra_report WHERE (((ra_report.CCENTER) Like "*" & [forms]![Search Cost Center]![Text30] & "*" Or (ra_report.CCENTER) Like "*" & [forms]![Search Cost Center]![Text31] & "*" Or (ra_report.CCENTER) Like "*" & [forms]![Search Cost Center]![Text32] & "*" Or (ra_report.CCENTER) Like "*" & [forms]![Search Cost Center]![Text33] & "*" Or (ra_report.CCENTER) Like "*" & [forms]![Search Cost Center]![Text34] & "*" Or (ra_report.CCENTER) Like "*" & [forms]![Search Cost Center]![Text35] & "*" Or (ra_report.CCENTER) Like "*" & [forms]![Search Cost Center]![Text36] & "*" Or (ra_report.CCENTER) Like "*" & [forms]![Search Cost Center]![Text37] & "*"));
This works great, except when one of the textboxes is empty. How would I code the following pseudo-code:
If textbox is not null, then use criteria OR If textbox is not null, then use criteria, etc
I'm not sure what I'd do - I suppose it depends on further details. If the
form was to create criteria for a report to run, I might build up a
where-string to open the report with. If it was simply to open a query, I
might re-write the query dynamically. This would allow me to optimize the
query based on what the user really wanted.
For example if we only three boxes were filled in the query would be:
SELECT * FROM ra_report WHERE CCENTER IN ("one","two","three")
but if one was used the query would be
SELECT * FROM ra_report WHERE CCENTER="one"
I realise I'm using exact matches, but the principal is the same. Would you
know how to dynamically re-write the query?
Anthony England wrote: "Drum2001" <dr******@gmail.com> wrote in message news:11**********************@j33g2000cwa.googlegr oups.com... SELECT ra_report.CCENTER,
FROM ra_report WHERE (((ra_report.CCENTER) Like "*" & [forms]![Search Cost Center]![Text30] & "*" Or (ra_report.CCENTER) Like "*" & [forms]![Search Cost Center]![Text31] & "*" Or (ra_report.CCENTER) Like "*" & [forms]![Search Cost Center]![Text32] & "*" Or (ra_report.CCENTER) Like "*" & [forms]![Search Cost Center]![Text33] & "*" Or (ra_report.CCENTER) Like "*" & [forms]![Search Cost Center]![Text34] & "*" Or (ra_report.CCENTER) Like "*" & [forms]![Search Cost Center]![Text35] & "*" Or (ra_report.CCENTER) Like "*" & [forms]![Search Cost Center]![Text36] & "*" Or (ra_report.CCENTER) Like "*" & [forms]![Search Cost Center]![Text37] & "*"));
This works great, except when one of the textboxes is empty. How would I code the following pseudo-code:
If textbox is not null, then use criteria OR If textbox is not null, then use criteria, etc
I'm not sure what I'd do - I suppose it depends on further details. If the form was to create criteria for a report to run, I might build up a where-string to open the report with. If it was simply to open a query, I might re-write the query dynamically. This would allow me to optimize the query based on what the user really wanted.
For example if we only three boxes were filled in the query would be: SELECT * FROM ra_report WHERE CCENTER IN ("one","two","three")
but if one was used the query would be SELECT * FROM ra_report WHERE CCENTER="one"
I realise I'm using exact matches, but the principal is the same. Would you know how to dynamically re-write the query?
No, I am not sure how to write the dymanic query...
"Drum2001" <dr******@gmail.com> wrote in message
news:11*********************@z34g2000cwc.googlegro ups.com... Anthony England wrote: "Drum2001" <dr******@gmail.com> wrote in message news:11**********************@j33g2000cwa.googlegr oups.com... > SELECT ra_report.CCENTER, > > FROM ra_report > WHERE (((ra_report.CCENTER) Like "*" & [forms]![Search Cost > Center]![Text30] & "*" Or (ra_report.CCENTER) Like "*" & > [forms]![Search Cost Center]![Text31] & "*" Or (ra_report.CCENTER) Like > "*" & [forms]![Search Cost Center]![Text32] & "*" Or > (ra_report.CCENTER) Like "*" & [forms]![Search Cost Center]![Text33] & > "*" Or (ra_report.CCENTER) Like "*" & [forms]![Search Cost > Center]![Text34] & "*" Or (ra_report.CCENTER) Like "*" & > [forms]![Search Cost Center]![Text35] & "*" Or (ra_report.CCENTER) Like > "*" & [forms]![Search Cost Center]![Text36] & "*" Or > (ra_report.CCENTER) Like "*" & [forms]![Search Cost Center]![Text37] & > "*")); > > > This works great, except when one of the textboxes is empty. How would > I code the following pseudo-code: > > If textbox is not null, then use criteria OR If textbox is not null, > then use criteria, etc
I'm not sure what I'd do - I suppose it depends on further details. If the form was to create criteria for a report to run, I might build up a where-string to open the report with. If it was simply to open a query, I might re-write the query dynamically. This would allow me to optimize the query based on what the user really wanted.
For example if we only three boxes were filled in the query would be: SELECT * FROM ra_report WHERE CCENTER IN ("one","two","three")
but if one was used the query would be SELECT * FROM ra_report WHERE CCENTER="one"
I realise I'm using exact matches, but the principal is the same. Would you know how to dynamically re-write the query?
No, I am not sure how to write the dymanic query...
If you put the DefineQuery function (shown below) into a separate module,
then you could generate the SQL based on which textboxes had been completed
and write something like
strSQL="SELECT Blah, blah, blah"
If Not DefineQuery("MyQuery",strSQL) Then
Exit Sub
End If
' If I'm here, then I've re-defined the query so go on
' and open the report, form or whatever
Public Function DefineQuery(strQueryName As String, _
strSQL As String) As Boolean
On Error GoTo Err_Handler
Dim dbs As DAO.Database
Dim qdf As DAO.QueryDef
Set dbs = CurrentDb
Set qdf = dbs.QueryDefs(strQueryName)
qdf.SQL = strSQL
DefineQuery = True
Exit_Handler:
If Not qdf Is Nothing Then
Set qdf = Nothing
End If
If Not dbs Is Nothing Then
Set dbs = Nothing
End If
Exit Function
Err_Handler:
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler
End Function
Anthony England wrote: "Drum2001" <dr******@gmail.com> wrote in message news:11*********************@z34g2000cwc.googlegro ups.com... Anthony England wrote: "Drum2001" <dr******@gmail.com> wrote in message news:11**********************@j33g2000cwa.googlegr oups.com... > SELECT ra_report.CCENTER, > > FROM ra_report > WHERE (((ra_report.CCENTER) Like "*" & [forms]![Search Cost > Center]![Text30] & "*" Or (ra_report.CCENTER) Like "*" & > [forms]![Search Cost Center]![Text31] & "*" Or (ra_report.CCENTER) Like > "*" & [forms]![Search Cost Center]![Text32] & "*" Or > (ra_report.CCENTER) Like "*" & [forms]![Search Cost Center]![Text33] & > "*" Or (ra_report.CCENTER) Like "*" & [forms]![Search Cost > Center]![Text34] & "*" Or (ra_report.CCENTER) Like "*" & > [forms]![Search Cost Center]![Text35] & "*" Or (ra_report.CCENTER) Like > "*" & [forms]![Search Cost Center]![Text36] & "*" Or > (ra_report.CCENTER) Like "*" & [forms]![Search Cost Center]![Text37] & > "*")); > > > This works great, except when one of the textboxes is empty. How would > I code the following pseudo-code: > > If textbox is not null, then use criteria OR If textbox is not null, > then use criteria, etc
I'm not sure what I'd do - I suppose it depends on further details. If the form was to create criteria for a report to run, I might build up a where-string to open the report with. If it was simply to open a query, I might re-write the query dynamically. This would allow me to optimize the query based on what the user really wanted.
For example if we only three boxes were filled in the query would be: SELECT * FROM ra_report WHERE CCENTER IN ("one","two","three")
but if one was used the query would be SELECT * FROM ra_report WHERE CCENTER="one"
I realise I'm using exact matches, but the principal is the same. Would you know how to dynamically re-write the query?
No, I am not sure how to write the dymanic query...
If you put the DefineQuery function (shown below) into a separate module, then you could generate the SQL based on which textboxes had been completed and write something like strSQL="SELECT Blah, blah, blah" If Not DefineQuery("MyQuery",strSQL) Then Exit Sub End If ' If I'm here, then I've re-defined the query so go on ' and open the report, form or whatever Public Function DefineQuery(strQueryName As String, _ strSQL As String) As Boolean
On Error GoTo Err_Handler
Dim dbs As DAO.Database Dim qdf As DAO.QueryDef
Set dbs = CurrentDb
Set qdf = dbs.QueryDefs(strQueryName)
qdf.SQL = strSQL
DefineQuery = True
Exit_Handler:
If Not qdf Is Nothing Then Set qdf = Nothing End If
If Not dbs Is Nothing Then Set dbs = Nothing End If
Exit Function
Err_Handler: MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number Resume Exit_Handler
End Function
Anthony,
My apologies to make this baby steps, but what would the query for SQL
be. I am kind of new to this... This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Robert Brown |
last post by:
suppose I have the following table:
CREATE TABLE (int level, color varchar, length int, width int, height
int)
It has the following rows
1, "RED", 8, 10, 12
2, NULL, NULL, NULL, 20...
|
by: Pete |
last post by:
Before I get started with the question, does anyone have a (single)
good book recommendation for database design? Not an Access-specific
book, but something geared toward helping me figure out...
|
by: John Baker |
last post by:
Hi:
I have a query which supports a form. Te form is used to edit, update and change records
in the table the query is based on. It all works fine EXCEPT that the "New" record (blank
updatable...
|
by: SD |
last post by:
Hello,
I have a form that has a panel container where I'm adding textboxes
dynamically based on a query to database, so I'm looping through the
records.
The problem I have is that once built,...
|
by: Drum2001 |
last post by:
I have a form that contains 8 textboxes "Textbox30, Textbox31,
Textbox32, Textbox33, Textbox34, Textbox35, Textbox36, Textbox37".
This form is designed to allow the user to input up to eight...
|
by: tizmagik |
last post by:
I am having a lot of difficulty generating a CrossTab Query based
report. I have looked online for several tutorials and whatnot but I
have not been able to really find what I'm looking for, nor...
|
by: rashmigaikwad |
last post by:
Hi All,
I need help in optimizing the query mentioned below:
SELECT
SUM(CASE WHEN PROD_TYP='HBRMC' AND INC_MULTIPLE < 2.50 AND LTV <= 0.75 OR LTV IS NULL THEN ADV_IN_QTR ELSE 0 END) ...
|
by: Drum2001 |
last post by:
I have a database where I need to query multiple items. Is it possible
to run a query based on a textbox where the information is delimited by
a comma.
Example:
Show me all names where...
|
by: mashimaro |
last post by:
Hi! I want to ask how can I get the record from the query. I currently have a form with 5 comboboxes and a button. After the user fills those 5 comboboxes and hit the button, a new form is opened...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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...
|
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: 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: 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...
| |