473,503 Members | 12,516 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using multiple field criteria from textboxs on Query form

36 New Member
Hello to the world of the wise,

I am a CSOM student at TRU. I am trying to design a database to improve my understanding.

The problem I am having is with setting up a query. I have a Query Form that has multilple controls to narrow the results of the query.

The functionality I am looking for is to allow a user to enter text into each of the textboxes or into couple or into none. Each textbox corresponds to a field in a Table.

I have tried:

Like '[Forms]![ReportPage]![StatusTextbox]' & '*' entered in a criteria line corresponding to the Status field.

I have also tried using doulbe quotes ( " ) instead of the single quotes ( ' ).

If I have information in each text box it returns the query executes perfectly. If I leave one textbox blank, no results are returned.

I am reletively new with access, but I do have some VB 2005 knowledge.

Once I have the correct format I will be able to apply it to each field

Any input would be greatly appreciated.

Thanks in advance
Jun 25 '07 #1
10 10107
JAM986
8 New Member
Hello to the world of the wise,

I am a CSOM student at TRU. I am trying to design a database to improve my understanding.

The problem I am having is with setting up a query. I have a Query Form that has multilple controls to narrow the results of the query.

The functionality I am looking for is to allow a user to enter text into each of the textboxes or into couple or into none. Each textbox corresponds to a field in a Table.

I have tried:

Like '[Forms]![ReportPage]![StatusTextbox]' & '*' entered in a criteria line corresponding to the Status field.

I have also tried using doulbe quotes ( " ) instead of the single quotes ( ' ).

If I have information in each text box it returns the query executes perfectly. If I leave one textbox blank, no results are returned.

I am reletively new with access, but I do have some VB 2005 knowledge.

Once I have the correct format I will be able to apply it to each field

Any input would be greatly appreciated.

Thanks in advance

Just curious, but how many fields are there for this particulary form? I have run into this situation some time back and will look to see if I can get specifics on it.
Jun 25 '07 #2
FNA access
36 New Member
Just curious, but how many fields are there for this particulary form? I have run into this situation some time back and will look to see if I can get specifics on it.
I have a :
- Date Start Textbox
- Date End Textbox
- Status Textbox
- Location Combobox
- Type Combobox
- Product # TextBox
- Model Name Combobox
Jun 25 '07 #3
JAM986
8 New Member
I have a :
- Date Start Textbox
- Date End Textbox
- Status Textbox
- Location Combobox
- Type Combobox
- Product # TextBox
- Model Name Combobox
1 last question (sorry, I should have included it in the original post). Is all the data in one table or spread across multiple tables?
Jun 25 '07 #4
FNA access
36 New Member
No problem, the help is greatly appreciated. All the information except the date field is stored in one table. The two tables are linked through an autonumber ID.

Thank you for taking the time to help me.
Jun 25 '07 #5
JAM986
8 New Member
No problem, the help is greatly appreciated. All the information except the date field is stored in one table. The two tables are linked through an autonumber ID.

Thank you for taking the time to help me.
No prob. I hope that I can. Anyway, in the code below I am searching for individuals by first AND last name OR by first name only or last name only. It then opens another form and the queried data is displayed on the newly opened form. I believe that it what you are doing with your data. Because you are using more criteria, it may be a bit more lengthy but this logic does work.

Options

1.You may want to consider using additional command buttons to narrow the criteria. For example, search by product ID and date or Model and Name brand...etc.
2. Another way that may help is to limit the search criteria to return more rows and let the user pick from that queried set.
3. In your code, check first to see if the fields are blank or not. Assign the textbox and combobox values to a variable(s) in the code. Which ever field is blank, assign a min/max value to that variable to return all rows. For example,

If !forms!frmGetData!textbox.ModelName = " " then
myVariableForModelName = "ZZZZZZZZZZ"
EndIf

Then execute your query after assigning all the blank form fields a value.

Hope This helps. Let me know.
----------------------------------------------------
Heres the code

Private Sub cmdSubmitINQ_Click()
On Error GoTo Err_cmdSubmitINQ_Click
'This procedure queries the for hire drivers based on their name
Dim stDocName As String
Dim stLinkCriteria As String
Dim strsql As String
Dim dbsn As Database
Dim NameFirst As String
Dim NameLast As String

NameFirst = Me!txtFHfirst & " "
NameFirst = "'" & NameFirst & "'" <----Single quote between two double quotes
NameLast = Me!txtFHlast & " "
NameLast = "'" & NameLast & "'" <----Single quote between two double quotes

Set dbsn = CurrentDb

strsql = "Select fname, lname, dob,fhNumber into LookupFH"
strsql = strsql & " From tblForHirePersonal"
strsql = strsql & " Where tblForHirePersonal.fname= " & NameFirst
strsql = strsql & " or tblForHirePersonal.lname= " & NameLast
dbsn.Execute strsql

DoCmd.Close
stDocName = "frmForHirePick"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Jun 25 '07 #6
FNA access
36 New Member
I will work with this in my code and try it out. With all my parameters it will be pretty big. Too bad I can't use a like in the criteria box in a query design. I'm a little confused with some parts.

How does ZZZZZZ return all values? Is there a certain number of them you should use? (ie 1 Z over 3 ZZZ)

Where does your code test for blanks so to return all values?
I see the if statement above, but don't see it implemented.

Thanks again
Jun 26 '07 #7
FNA access
36 New Member
I will work with this in my code and try it out. With all my parameters it will be pretty big. Too bad I can't use a like in the criteria box in a query design. I'm a little confused with some parts.

How does ZZZZZZ return all values? Is there a certain number of them you should use? (ie 1 Z over 3 ZZZ)

Where does your code test for blanks so to return all values?
I see the if statement above, but don't see it implemented.

Thanks again
I figured out some code to place in the criteria lines of the query builder to save the manual coding.

I used :

Criteria Like [Forms]![ReportPage]![LocationCombobox] & '*'
or [Forms]![ReportPage]![LocationCombobox] is Null

With this I can either have data in to limit the scope or I can leave blank to retrieve all info.

I placed this code in each one of my criteria boxes. One of my criteria must be entered (TypeCombobox).

Thank you very much for your time
Jun 26 '07 #8
FNA access
36 New Member
I figured out some code to place in the criteria lines of the query builder to save the manual coding.

I used :

Criteria Like [Forms]![ReportPage]![LocationCombobox] & '*'
or [Forms]![ReportPage]![LocationCombobox] is Null

With this I can either have data in to limit the scope or I can leave blank to retrieve all info.

I placed this code in each one of my criteria boxes. One of my criteria must be entered (TypeCombobox).

Thank you very much for your time

Never Mind it doesn't work all the time. I found some faults in it. Will keep working on it.
Jun 26 '07 #9
JAM986
8 New Member
Never Mind it doesn't work all the time. I found some faults in it. Will keep working on it.
Sorry,
been away from the computer for a while. Let me give you an example that I experimented with using first and last names.

If the first name is left blank and only the last name has a value, I would assign the value "ZZZZZZZZ" to the first name then query everything where the first name is LESS that the value I have assigned it thus returning all rows where I have a match on the last name. Same sort of way you would do with 2 date fields by assigning a blank beginning date the value 01/01/1001 and the ending date field a date in the future.

Hope this makes it a little clearer.

I'll check in more frequently with ya. Its been a busy last couple of days
Jun 27 '07 #10
MMcCarthy
14,534 Recognized Expert Moderator MVP
Without seeing your full query it's difficult to say but I would guess something like the following would work

Like IIf([Forms]![ReportPage]![StatusTextbox]="","*",[Forms]![ReportPage]![StatusTextbox] & "*")
Jun 29 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

1
20742
by: KLAU | last post by:
I have a field that retrieves information from an expression in a query. I have used a DLookup function to get the calculated field from the query. However, the relationship is 1-to-many so one...
4
7135
by: meganrobertson22 | last post by:
Hi Everyone- I have a question about how to add and then use the "All" selection in a combo box. I am trying to figure out how to: (1) add "All" as a selection to a combo box and then (2)...
7
25714
by: Daron | last post by:
In my SQL I have a column that returns a boolean value (-1 or 0), no problem. I need to be able to only see the records that return a 0 (False). I can sort and bring these to the top. When I...
7
31984
by: Michael R | last post by:
Good afternoon. I'm stucked in composing the syntax for DCount expression in a select query. The query qryCustomers has CustomerID field, the DCount function uses tblLoans with LoanDate and Id fields...
3
1280
by: jm | last post by:
Hi, I have a form that I need to search several with several items, some together and some separate. Say I have a date, lastname, and invoice and I want to search on any of these individually. ...
2
2567
by: Ru55ell | last post by:
Hi I have written a form that has 4 drop down selection boxes on it, with check boxes next to them. When a user selects something from the drop down box the check box is automatically selected. I...
2
1951
by: ziccardi | last post by:
When my query is executed it produces no results. However, if I copy and paste the criteria from the information populated and referenced in my query, it works fine. The criteria needs to be...
21
4458
sueb
by: sueb | last post by:
I have a form/subform arrangement where the parent form has a Patient_Type that I want to translate into a Hospital_Category based on an existing lookup table. The relationship between Patient_Type...
0
7212
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
7098
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
7296
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
7364
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
5604
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,...
0
4696
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...
0
3174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
751
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
405
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.