I have a search form that searches for the criteria selected. I'm want to get the search method to look into multiple textboxes instead of just one. Please help I'm fairly new to Access/VBA. My code is the following but it does not work when a certain tool which is in [tool2] or {tool3] etc. It just seems like it only looks at [tool1] and if it does not find it there it just stops there. - Private Sub cmdFind_Click()
-
Dim varwhere As Variant
-
Dim rst As DAO.Recordset
-
'Initialize to Null
-
varwhere = Null
-
-
If IsNull(Me![Keyword]) Or (Me![Keyword]) = "" Then
-
MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criteria!"
-
Me![Keyword].SetFocus
-
Exit Sub
-
End If
-
-
If SortBy = "Tools" Then
-
varwhere = (varwhere + " AND ") & "[tools1] & [tool2] & [tool3] LIKE '" & Me.Keyword & "*'"
-
Set rst = DBEngine(0)(0).OpenRecordset("SELECT * FROM customers WHERE " & varwhere)
-
If rst.RecordCount = 0 Then
-
Set rst = DBEngine(0)(0).OpenRecordset("SELECT * FROM customers WHERE " & varwhere)
-
MsgBox "No Access Card Found.", vbInformation, gstrAppTitle
-
rst.Close
-
Set rst = Nothing
-
Exit Sub
-
End If
-
-
rst.MoveLast
-
DoCmd.OpenForm "searchresults", WhereCondition:=varwhere
-
Forms!Searchresults.SetFocus
-
DoCmd.Close acForm, Me.Name
-
'Clean up recordset
-
rst.Close
-
Set rst = Nothing
-
Exit Sub
-
End If
6 1776
First of all, please use the [code] tags provided! Simply select your code and click the # icon on the top of the reply window. You are unlikely to get any help at all if you simply post a block of code without the tags.
Second: take a careful look at line 14. If you notice, you have spelled [tools1] and [tool2] and [tool3]. Check to make absolutely sure that you have spelled them correctly, also, what are they? Text box controls, variables?? If they are text box controls, you will notice that the code highlighter indicates they are being treated as part of a string... You'll need to split them out from the string if you are trying to capture values from text boxes on the form.
Regards,
Scott
NeoPa 32,556
Expert Mod 16PB - Private Sub cmdFind_Click()
-
Dim varwhere As Variant
-
Dim rst As DAO.Recordset
-
'Initialize to Null
-
varwhere = Null
-
-
If IsNull(Me![Keyword]) Or (Me![Keyword]) = "" Then
-
MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criteria!"
-
Me![Keyword].SetFocus
-
Exit Sub
-
End If
-
-
If SortBy = "Access Card" Then
-
varwhere = (varwhere + " AND ") & "[tool1] & [tool2] & [tool3] LIKE '" & Me.Keyword & "*'"
-
Set rst = DBEngine(0)(0).OpenRecordset("SELECT * FROM customers WHERE " & varwhere)
-
If rst.RecordCount = 0 Then
-
Set rst = DBEngine(0)(0).OpenRecordset("SELECT * FROM customers WHERE " & varwhere)
-
MsgBox "No tools found.", vbInformation, gstrAppTitle
-
rst.Close
-
Set rst = Nothing
-
Exit Sub
-
End If
-
-
rst.MoveLast
-
DoCmd.OpenForm "searchresults", WhereCondition:=varwhere
-
Forms!Searchresults.SetFocus
-
DoCmd.Close acForm, Me.Name
-
'Clean up recordset
-
rst.Close
-
Set rst = Nothing
-
Exit Sub
-
End If
Sorry about that im new to this i don't really have much knowledge of how to post. Regarding the textboxes they are in a table called customers and basically we enter what kind of tool the customer has. If i just search for just one variable like [tool1] then the search works perfectly but not always is going to be in [tool1] it could be in [tool2] or [tool3] etc. What i would is for the search method to look at all of these fields if possible and not just one textbox.
NeoPa 32,556
Expert Mod 16PB
Your WHERE clause needs to be of the form : - [Tools1] Like 'XYZ*' AND [Tools2] Like 'XYZ*' AND [Tools3] Like 'XYZ*'
& is a string concatenation character.
Your WHERE clause needs to be of the form : - [Tools1] Like 'XYZ*' AND [Tools2] Like 'XYZ*' AND [Tools3] Like 'XYZ*'
& is a string concatenation character.
Thank you so much for your help. I really appreciate it, to think that i have spent hours and hours trying to figure this out. Finally it works. Once again i thank you so much.
NeoPa 32,556
Expert Mod 16PB
No worries.
There is an article ( Finding Jet SQL Help) that you may find useful for similar issues. The Help's not easy to find but it does have a lot of very useful information in it.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Les Juby |
last post by:
A year or two back I needed a search script to scan thru HTML files
on a client site. Usual sorta thing. A quick search turned up a
neat script that provided great search results. It was fast,...
|
by: CharitiesOnline |
last post by:
Hello,
I have set this script up to add paging to a search results page. Which on
the first page works fine. I calculates how many pages there should be
depending on the number of results returned...
|
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...
|
by: Christopher Koh |
last post by:
I will make a form which will search the database (just like google
interface) that will look/match for the exact name in the records of a
given fieldname. Any suggestions on how to make the code?
|
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...
|
by: tshad |
last post by:
Can you do a search for more that one string in another string?
Something like:
someString.IndexOf("something1","something2","something3",0)
or would you have to do something like:
if...
|
by: Arun Nair |
last post by:
Hi,
I have an Employerregistration pagethat is used to add new Empoyers
to a table. I also have another form search.aspx used to search the
employers(based on their id) and edit the employer...
|
by: Dica |
last post by:
i apologize for what is no doubt a very rudimentary question, but i'm still
trying to wrap my brain around .net coding habits. in classic asp, if i
wanted to show search results, i'd just post the...
|
by: Merlin1857 |
last post by:
How to search multiple fields using ASP
A major issue for me when I first started writing in VB Script was constructing the ability to search a table using multiple field input from a form and...
|
by: iahamed |
last post by:
Hi Everyone,
I got two parts of my advance search to work, I am running out of Logic to
connect the third. My mind is in swing! Pleaseeeeeeeee Help me.
I have 3 Fiels to search, the First two...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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: 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...
|
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...
| |