After making some small chages to my search code I have found that my search is now returning incorrect results.
What is suppposed to happen is that when I search for a value in the volume field the search is supposed to return all results that match the full or partial search term (using "like" criteria in my query)
What is actually happening is that the search is only matching exact search criteria.
Any partial search requests result in the msgbox stating no matching results found.
This is the code that is found in the query for the volume field:
The above code is actually present on about 4 diff lines in the query tab.Like [Forms]![search]![volume] & "*"
I could post a screenshot later if reqd.
Are you trying to get results that contain the criteria in any part of the volume? ie. you put in sugar in the search box and are looking for the results to be maple sugar syrup, sugar pops, candy sugars, etc. So sugar can be at the beginning, middle or end of the volume? If this is the case, then you need to add an "*" & right after Like, so that Access knows this. Right now it is only looking for volumes that begin with sugar (if you use my example)
Alan
Alan
Click the * below to say thanks.
Database Principles
Pivot Table Tips
Good Excel Video Tutorials
Sumifs or SumProduct
DataPig Access Tutorials
MS Query Tutorial
Worst Pie Chart Ever?
Yes the results returned are supposed to be any results that include the partial search criteria used in the search form.
Will have a look at that and post back.
Tried what you suggested and it still doesn't seem to work like it's supposed to .
This is what it looks like after I made the change:
The strange thing is - the query line for the title field search is exactly the same as the old line for the volume search ... and it works perfectly as expected.Like "*" & [Forms]![search]![volume] & "*"
and the old volume field lineLike [Forms]![search]![title] & "*"
I really don't understand why changing the data type on the volume field in the table would have caused this problem.Like [Forms]![search]![volume] & "*"
A couple of questions.
- What was your data type before the change
- what is your data type now
- are you using a combo box to make your selection
- if you are using a combo box, is the related lookup table linked to your query
Alan
Alan
Click the * below to say thanks.
Database Principles
Pivot Table Tips
Good Excel Video Tutorials
Sumifs or SumProduct
DataPig Access Tutorials
MS Query Tutorial
Worst Pie Chart Ever?
1. The data type was numeric
2. The data type is now text.
3. No it's just a text box.
4. irrelevant because i'm not using a combo box
I don't have a definitive answer so I am grasping for straws at this time. Try changing the second '!' in your Like criteria to a '.' The one between the form name and the field name. I know that they are sometimes interchangeable and really shouldn't make a difference, but sometimes Access does some strange things also.
Alan
Alan
Click the * below to say thanks.
Database Principles
Pivot Table Tips
Good Excel Video Tutorials
Sumifs or SumProduct
DataPig Access Tutorials
MS Query Tutorial
Worst Pie Chart Ever?
ok will try it and get back to you
Did you mean to change this:
to this:Like "*" & [Forms]![search]![volume] & "*"
I have done this but am now getting a runtime error that will not allow me to test it.Like "*" & [Forms]![search].[volume] & "*"
Runtime error 2004: There isn't enough memory to perform the operation. Close unnecessary programs and try again
The highlighted debug line is:DoCmd.OpenForm "search results"
I did try and add more tables, fields and forms to the database but surely access would be able to cope with modification of the files in this fashion ?
Last edited by vampyr07au; 05-28-2011 at 12:38 PM.
This ispart of the code behind your command button to run the search?
Are you able to post the entire code for that command button?
The highlighted debug line is:
Code:
DoCmd.OpenForm "search results"
Also, are you running the query from the QBE or from a SQL Statement in VBA?
If from the QBE, would you post the entire SQL statement for the Query? Having bits and pieces doesn't give us the whole story.
Alan
Last edited by alansidman; 05-29-2011 at 06:42 AM.
Alan
Click the * below to say thanks.
Database Principles
Pivot Table Tips
Good Excel Video Tutorials
Sumifs or SumProduct
DataPig Access Tutorials
MS Query Tutorial
Worst Pie Chart Ever?
Here is the code for the command button
Private Sub Find_Click() Dim strCriteria As String If Len(Me.Volume & vbNullString) > 0 Then strCriteria = strCriteria & "[Volume] = '" & Me.Volume & "' AND " End If If Len(Me.Title & vbNullString) > 0 Then strCriteria = strCriteria & "[Movie Title] " & SQLQuote(Me.Title, True, True) & " AND " End If If Len(Me.Rating & vbNullString) > 0 Then strCriteria = strCriteria & "[Rating] = '" & Me.Rating & " ' AND " End If If Len(strCriteria) < 1 Then MsgBox ("Please enter search criteria before attempting to search the database") Else strCriteria = Left(strCriteria, Len(strCriteria) - 5) If DCount("*", "search", strCriteria) = 0 Then MsgBox "No movies matching your search. Please refine your search and try again." Exit Sub Else DoCmd.OpenForm "search results" End If End If End Sub
As to your other question about how the query is being called, I must profess to not actually knowing that.
As far as I was aware the query is being run from within the above code or when the
line runs.DoCmd.OpenForm "search results"
The out of memory error is only occurring when an attempt to open that particular form and it doesnt matter if the attempt is made via the button or by trying to dbl click the form in the object list on the left hand side.
Any other form opens perfectly well.
I can provide a copy of the entire project if it would make things easier ?
Can you try storing the entire search phrase as a variable so you can check the variable before running the query? Something like this:
Then useDim strVol As String strVol = "*" & [Forms]![search]![volume] & "*"and the immediate window to find what you are actually searching with.debug.print strVol
Also be aware that you query needs to be updated to search for text. Since you were using numbers before, your query would have been something like:
but now it needs to be like this:"SELECT * FROM tbl WHERE field1 LIKE " & [Forms]![search]![volume]
where the variable is surrounded by single quotes."SELECT * FROM tbl WHERE field1 LIKE '" & [Forms]![search]![volume] & "'"
Is your code running too slowly?
Does your workbook or database have a bunch of duplicate pieces of data?
Have a look at this article to learn the best ways to set up your projects.
It will save both time and effort in the long run!
Dave
In relation to the below comment - wrapping it in the single quotes makes sense since that is what was reqd in the code found in the cmd button that controls the search however I do not understand wherecame from?SELECT * FROM tbl WHERE field1
The query is simply this:Also be aware that you query needs to be updated to search for text. Since you were using numbers before, your query would have been something like:
but now it needs to be like this:"SELECT * FROM tbl WHERE field1 LIKE " & [Forms]![search]![volume]
where the variable is surrounded by single quotes."SELECT * FROM tbl WHERE field1 LIKE '" & [Forms]![search]![volume] & "'"Like "*" & [Forms]![search].[volume] & "*"
Last edited by vampyr07au; 05-31-2011 at 10:18 PM.
I just put a generic sql statement in.
is not a valid SQL statement, it is just part of a WHERE clause. What is you whole SQL statement?Like "*" & [Forms]!]![search].[volume] & "*"
Is your code running too slowly?
Does your workbook or database have a bunch of duplicate pieces of data?
Have a look at this article to learn the best ways to set up your projects.
It will save both time and effort in the long run!
Dave
I'm sorry i'm still a little lost - I'm very new to all of this and have been using a lot of stuff that was provided to me after asking for assistance.
The line
is what is found in the query section of my database project in the column for the volume field.Like "*" & [Forms]!]![search].[volume] & "*"
As previously stated I can provide a copy of the entire project if it will make things easier.
I'm not sure where the sql statement would be ... there is the query and there is code that operates after clicking a search button, that's all I know.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks