473,396 Members | 1,599 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.

Like operator with unbound text boxes

I have a continuous form set as a modal type. In the detail section of the form I have the following bound fields: RecordNumber, JobName & ContractorsBidding. The header of the form contains text boxes to accept input from the client to perform a search on any of these three fields. The action button in the header is set to perform a filter to display the requested search. The eventual goal is to allow the user to select the record from the search results and display it in a separate form. I am unable to get the Like operator to display more than a single record and the search criteria has to be entered exactly. When I try to add the "*" & into the code, a type mismatch is generated. This is what I have so far:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdSearch_Click()
  2. DoCmd.ApplyFilter "", _
  3.        "([RecordNumber] = [Forms]![frmJobSearch]![txtRecordNumber] " & _
  4.       "Or IsNull([Forms]![frmJobSearch]![txtRecordNumber]))" & _
  5.    "And ([JobName] Like [Forms]![frmJobSearch]![txtJobName] " & _
  6.       "Or IsNull([Forms]![frmJobSearch]![txtJobName]))" & _
  7.    "And ([ContractorsBidding] Like [Forms]![frmJobSearch]![txtContractor] " & _
  8.       "Or IsNull([Forms]![frmJobSearch]![txtContractor]))", ""
  9. End Sub
Apr 3 '16 #1
6 1636
NeoPa
32,556 Expert Mod 16PB
Check out Example Filtering on a Form.
Apr 3 '16 #2
Thanks for the input. I'm not 100% with how it works yet but will take a go at it. Would you happen to know why with what I had put together would only show results if for example the full job name was entered into the text box?
Apr 4 '16 #3
NeoPa
32,556 Expert Mod 16PB
JalBright:
Would you happen to know why with what I had put together would only show results if for example the full job name was entered into the text box?
Oh yes. That's because you haven't used any wildcard characters.

Using Like with a value without wildcards is equivalent to using Equals.
Apr 4 '16 #4
I thought I had understood that and so didn't think it would be an issue to add a wildcard but when I do, I get a type mismatch error. In attempting to search for anything similar as in this:
Expand|Select|Wrap|Line Numbers
  1. "And ([JobName] Like "*" & [Forms]![frmJobSearch]![txtJobName]  " & "*" & _
  2.       "Or IsNull([Forms]![frmJobSearch]![txtJobName]))" & _
Apr 5 '16 #5
NeoPa
32,556 Expert Mod 16PB
But that's all wrong. Look at where all the double-quotes (") are in that code. They don't match up, and where they are is not what you want. You can't be sloppy with code. It has to be exactly what you want, or it just won't work.
Apr 5 '16 #6
NeoPa
32,556 Expert Mod 16PB
Also, it's much easier to use Nz() than having two distinct comparisons for a single field. In this case, even that is redundant as you can use Null propagation (Using "&" and "+" in WHERE Clause). EG.
Expand|Select|Wrap|Line Numbers
  1. AND ([JobName] Like '*'+[Forms]![frmJobSearch]![txtJobName]+'*')
The + operator uses Null propagation so that if either side is Null then the result also is.

As it happens, when I look back, I see that it's even easier than that, as you don't want to use Null propagation. For your requirements you just use the ampersand (&) to create the string and you end up with '**' (IE. All records) if the control is Null :
Expand|Select|Wrap|Line Numbers
  1. AND ([JobName] Like '*' & [Forms]![frmJobSearch]![txtJobName] & '*')
Apr 5 '16 #7

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

Similar topics

2
by: John Kreps | last post by:
(acc 2002) I've got six unbound text boxes on a subform that has a white background. Each of those six boxes has an expression that when true, will change its background from white to another...
2
by: Jayjay | last post by:
I've got a report that has a series of unbound text boxes that are being populated by some variables in code. The format is supposed to be a currancy format, but on a certain series of boxes, I...
7
by: Aravind | last post by:
Hi folks. I have 2 forms, frmBorrow and frmHistory frmBorrow has an unbound multi-column combo box (cboMember) and 7 unbound text boxes (MemNo, MemName, MemIC, MemType, CourseFaculty, Borrow,...
11
by: amanda27 | last post by:
I have a form and there are some text boxes that show a score depending on what someone picks in the drop down next to that box. I did this part with some coding and therefore, for example if they...
11
by: jwessner | last post by:
I have a form (Form1) which contains basic Project data and a subform listing the personnel assigned to the Project as a continuous form. Selecting a person on that project and clicking on a command...
7
by: HSXWillH | last post by:
I am designing an inventory system and am stuck on a potential problem. I have a table of Stock_Catalog containing the following fields: Stock_ID (random autonumber), Full_Desc, Serial, Auto,...
2
topher23
by: topher23 | last post by:
Disclaimer: I've already come up with a solution for this issue, but I thought I'd post it in the hope that it could help someone else and on the off chance that someone has another solution. I...
1
by: Lordoasis | last post by:
I will appreciate some assistance with a project of mine. I am relatively new to access. I have a form with unbound text boxes. I want to be able to search for member IDs with one of the unbound...
7
by: aannll | last post by:
hiiii i have form(Main form) that contain textboxes(f1,f2) and a button (f3) when enter values to text boxes and click the button i want the values saved in fields(Passwords,Names) that Exists in...
6
by: James Armstrong | last post by:
Hi guys, I'm trying to write a module that will run through a form I have with 20 unbound text boxes in it and write the values in the text boxes that aren't null to a temporary table. For...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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.