473,396 Members | 2,011 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.

Problem with Keyword search after updateing to 2007

112 100+
I have a keyword search button on my databases footer bar which when clicked opens a pop-up box that you can type a key word into. When the keyword is entered it put it into a query that filters my form to that keyword in several fields. Problem is that since my upgrade to 2007, it only works the first time. If you try to use it again it does not display the pop-up box and just re-filters for the first work you typed. The only way around this is a full shut down and restarts which is getting annoying! I did not write this code and I am not sure how to fix it, any help would be greatly appreciated! Code is below.

Thanks


Expand|Select|Wrap|Line Numbers
  1. Private Sub Keyword_Search_Click()
  2. On Error GoTo Err_Keyword_Search_Click
  3.  
  4.     Dim stLinkCriteria As String
  5.  
  6.     'DoCmd.Close acForm, "frmDescription"
  7.     Forms("frmDescription").Refresh
  8.     'DoCmd.Close acForm, Me.Name
  9.     DoCmd.OpenForm "frmDescription", , "qryKeyword", stLinkCriteria
  10.  
  11.  
  12. Exit_Keyword_Search_Click:
  13.     Exit Sub
  14.  
  15. Err_Keyword_Search_Click:
  16.     MsgBox Err.Description
  17.     Resume Exit_Keyword_Search_Click
  18.  
  19. End Sub
May 26 '09 #1
31 2598
puppydogbuddy
1,923 Expert 1GB
It sounds like you need to clear your search results before proceeding with a new search. Please post the sql for qrykeyword, and the code relating to the build of stLinkCriteria.
May 26 '09 #2
Redbeard
112 100+
Here is the SQL for the Keyword query:
Expand|Select|Wrap|Line Numbers
  1. SELECT *
  2. FROM fullqry
  3. WHERE (((fullqry.Description) Like "*" & [Enter keyword: ] & "*")) OR (((fullqry.History) Like "*" & [Enter keyword: ] & "*")) OR (((fullqry.[Object Name]) Like "*" & [Enter keyword: ] & "*")) OR (((fullqry.[Object Type]) Like "*" & [Enter keyword: ] & "*")) OR (((fullqry.[Subject/Image]) Like "*" & [Enter keyword: ] & "*")) OR (((fullqry.[Photo Keywords]) Like "*" & [Enter keyword: ] & "*"))
  4. ORDER BY Mid(Replace(Description.[Accession Number],'X',''),1,4), Mid(Replace(Description.[Accession Number],'D',''),1,4), Mid(Replace(Description.[Accession Number],'DX',''),2,5);
and her is the code relating to the build of stLinkCriteria:
Expand|Select|Wrap|Line Numbers
  1. Like "*" & [Enter keyword: ] & "*"
I never had a problem untill I upgraded to 2007?
May 26 '09 #3
NeoPa
32,556 Expert Mod 16PB
@Redbeard
I don't understand why. The quotes are missing from this. It should read :
Expand|Select|Wrap|Line Numbers
  1. Like "'*" & [Enter keyword: ] & "*'"
May 26 '09 #4
Redbeard
112 100+
I tried adding the quotes like you suggested NeoPa, but it now does not work at all? I just get 0 records and I still have the same problem.
May 26 '09 #5
puppydogbuddy
1,923 Expert 1GB
stLinkCriteria looks like duplication of what is in fullquery. Try it without stLinkCriteria.

Change this:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenForm "frmDescription", , "qryKeyword", stLinkCriteria 
To this:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenForm "frmDescription", , "qryKeyword" 
May 26 '09 #6
NeoPa
32,556 Expert Mod 16PB
@Redbeard
Am I going mad?

Can anyone else see something I've missed :S
May 26 '09 #7
Stewart Ross
2,545 Expert Mod 2GB
The SQL as originally posted was correct, NeoPa. It was not a string built in VBA, where the literal would indeed be placed inside single quotes, but SQL direct from the query grid. The syntax used is correct when using a parameter preceded and followed by the wildcard character, and works flawlessly in my tests in A2003.

Given a value for the parameter, the Like clause just becomes something along the lines of

Like "*Some Value*"

Access will happily accept single quotes in place of the double quotes for the same purpose, but the query grid editor places double quotes around string literals by default when they are typed into the criteria part of the grid.

Just a guess, but perhaps RedBeard could substitute single-quotes in place of the double-quotes in the Access 2007 version, to see if the original problem relates to previous versions of Access accepting double quotes when single quotes should be preferred (if 2007 is sticking closer to ANSI SQL standards).

For some back-end databases (such as SQL Server if memory serves) the wild card character is "%" and not "*", but as this problem started with the upgrade to A2007 I doubt that the choice of wildcard is the problem.

-Stewart
May 27 '09 #8
FishVal
2,653 Expert 2GB
@ Redbeard

Could it be so that when you run DoCmd.OpenForm second time [frmDescription] instance, created by the first call, has not been unloaded?
May 27 '09 #9
Redbeard
112 100+
I have changed the quotes to singles like Stewart Ross suggested and got rid of the stLinkCriteria like puppydogbuddy suggested but it was still not letting me enter a Keyword the second time around. So I have modified the code to work but not really happy with how it is doing it. Here is the code now:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Keyword_Search_Click()
  2. On Error GoTo Err_Keyword_Search_Click
  3.  
  4.     DoCmd.Close acForm, "frmDescription"
  5.     DoCmd.OpenForm "frmDescription", , "qryKeyword"
  6.  
  7. Exit_Keyword_Search_Click:
  8.     Exit Sub
  9.  
  10. Err_Keyword_Search_Click:
  11.     MsgBox Err.Description
  12.     Resume Exit_Keyword_Search_Click
The form is now closing and then asking me for my keyword and then reopening when I entre one. This seems to get rid of the problem as it will let me entre a new keyword each time but the opening and closing of the form is a little time consuming and not visually appealing. Does anyone see a way around this?

Thanks for the help so far.
May 27 '09 #10
Stewart Ross
2,545 Expert Mod 2GB
I'd suggest using a different approach; there is no need to keep opening and closing the form if what you are doing is to apply a filter based on a keyword entered in response to code running in another form. Use a separate routine to open the form just the once (without a filter applied in the first instance), or just open the form if it is not already loaded. Then, your keyword entry response routine just has to apply a filter to the form - no need to close it and reopen it., This is done using the form's Filter and FilterOn properties to set and apply the keyword filter.

You will need to supply the form's full name if you are applying a filter from outside of the form itself, like this:

Expand|Select|Wrap|Line Numbers
  1. with forms![name of your form]
  2.     .filter = strYourFilterString
  3.     .filteron = true
  4.  end with
-Stewart
May 27 '09 #11
NeoPa
32,556 Expert Mod 16PB
@Stewart Ross Inverness
I was having brain problems that day Stewart. You're absolutely correct of course and it makes perfect sense when I look at it now.
May 27 '09 #12
NeoPa
32,556 Expert Mod 16PB
@Stewart Ross Inverness
I would suggest looking at ANSI Standards in String Comparisons.

Later versions of Access can be set to use those more recent standard settings also, thus leaving older code to flounder.
May 27 '09 #13
puppydogbuddy
1,923 Expert 1GB
Assuming that frmDescription is already opened and that qryKeyword is the record source of frmDescrption

try changing this:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.Close acForm, "frmDescription" 
  2. DoCmd.OpenForm "frmDescription", , "qryKeyword" 
to this:
Expand|Select|Wrap|Line Numbers
  1. Forms!frmDescription.RecordSource = ""
  2. Forms!frmDescription.RecordSource = "qryKeyword"
May 28 '09 #14
Redbeard
112 100+
Ok, so I started with puppydogbuddy fix as it seemed the simplest but it causes issues with other code and will not run. Also it is not based on the same query as the main form, tried to change the query to the same one as the main form but same results. I have also looked at Stewart Ross suggestion but I don't know enough about programming to figure out how to use it. I was original hopping that it was just a matter of a simple fix to my code like 2003 use one thing and 2007 uses another, but it seem to be a complete rewrite. So if there is anyone that has a code that will do what I want that would be great. Essentially I have my main form "frmDescription" which is up. I have a Keyword button at the bottom on my footer bar. When I click the button I want to have a pop-up ask me for a keyword that when entered looks for that keyword in 5 different fields on my main form and filters out the appropriate records. As I said above, I am not a programmer and have very limited knowledge about how these things work, so if possible please explain in simplest terms.

Thanks again for all the help.
May 28 '09 #15
NeoPa
32,556 Expert Mod 16PB
Can you provide meta-data for the form that you are hoping to filter. This may be a query or a table, but we would need to know its name and the fields it contains.

This will work much better if you can post the meta-data (info about the layout / structure) of the table in the same way as I use in my example. Click on the Reply button and you will have access to all the codes I've used. PK & FK stand for Primary Key & Foreign Key respectively. Please don't use any TABs in your formatted layout as this will not display correctly - Spaces only for layout.
Table Name=[tblStudent]
Expand|Select|Wrap|Line Numbers
  1. Field           Type        IndexInfo
  2. StudentID       AutoNumber  PK
  3. Family          String      FK
  4. SName           String
  5. University      String      FK
  6. Mark            Numeric
  7. LastAttendance  Date/Time
May 28 '09 #16
Redbeard
112 100+
Hi Neopa

The form that I am using is called "frmDescription" and it is run off a query call "fullqry" which is taking info from 10 tables and has over 50 fields. Do you want the meta-data from every field in the Query or Form? And if so how do I get that?
May 28 '09 #17
NeoPa
32,556 Expert Mod 16PB
@Redbeard
  1. Not all no. With that many it would be helpful if you included only the relevant ones. That should cover any that may be used in filtering or sorting.
  2. To get the list of fieldnames you can run the query, copy the results and paste into Excel.
    From Excel you can copy just the title row then use Paste Special / Values / Transpose to provide the list in a column.
    This can then be Copy / Pasted as text.
May 28 '09 #18
Redbeard
112 100+
These are the feilds in the "fullqry" that I want to filter my Keyword search through:

Expand|Select|Wrap|Line Numbers
  1. Feilds                  Type              IndexInfo
  2. Description             Memo
  3. History                 Memo
  4. Object Name             Text
  5. Object Type             Text
  6. Subject/Image           Text 
  7. Photo Keywords          Text
I don't think any of the have IndexInfo as that is what links tables together?
May 29 '09 #19
NeoPa
32,556 Expert Mod 16PB
Thanks for this and well done (you did a fine job - so many fail to get this right).

I'm just setting up some tests now, but I think I'm right in saying (will confirm later) that filtering is not possible on Memo fields.

FYI. Index Info is useful for linking tables, but is certainly not limited to that single application.
May 29 '09 #20
NeoPa
32,556 Expert Mod 16PB
Well, that proved a failure (in as much as the Memo field I tried it with worked perfectly).

OK. Let me see if I can put together some SQL to fit this, then we can see if we can determine exactly what is causing your problem. I have some suspicions now, but I suggest we take it step-by-step otherwise we'll get out of synch and confused.
May 29 '09 #21
NeoPa
32,556 Expert Mod 16PB
Try this and explain where, if anywhere, there are problems. This is actually very similar to the SQL you posted in post #3.
Expand|Select|Wrap|Line Numbers
  1. SELECT   *
  2.  
  3. FROM     [FullQry]
  4.  
  5. WHERE  (([Description] Like '*' & [Enter keyword: ] & '*')
  6.    OR   ([History] Like '*' & [Enter keyword: ] & '*')
  7.    OR   ([Object Name] Like '*' & [Enter keyword: ] & '*')
  8.    OR   ([Object Type] Like '*' & [Enter keyword: ] & '*')
  9.    OR   ([Subject/Image] Like '*' & [Enter keyword: ] & '*')
  10.    OR   ([Photo Keywords] Like '*' & [Enter keyword: ] & '*'))
I expect you'll see similar problems to before, but check it carefully anyway if you would.
May 29 '09 #22
Redbeard
112 100+
Ok, so I tried it and got the same results. It works the first time but when you try it again there is no pop-up box that asks you to type in a keyword and it automatically re-filters for the keyword you typed the first time. It seems to be that we just need to figure out how to clear the keyword out of the filter? Otherwise it works fine.
May 29 '09 #23
NeoPa
32,556 Expert Mod 16PB
Right, this is what I was sort of expecting.

What I think is happening is that, just as when you enter a prompt in SQL many times, the SQL engine recognises this and optimises the situation by asking for it only once, A2007 is also (it seems) trying to be clever and optimising out the prompt for the value across multiple runs when it determines that it has a value for that already. trying to be too clever it would seem.

I suggest, to get around this, that you take the form based approach instead.

Write your SQL to refer instead to a TextBox on an open form. That way the operator can change this before the query (report whatever) is run. This can also be set up so that the query is run from a command button on the same form.

Does this sound like a plan?
May 29 '09 #24
Redbeard
112 100+
So you are suggesting that I create a form with a text box that is my keyword entre point, that is connected to my main form by a button on the footer bar. When a click the button on the footer bar the new form with text box pops up and askes for a keyword. When I entre one is runs the query that filters my main form. So that each time I get the option to entre a new keyword. Is this right? If so how do I link the text box on my new form to the query that I am running?
May 29 '09 #25
NeoPa
32,556 Expert Mod 16PB
Almost.

I would consider adding an unbound TextBox onto your main form if that is where you start the process from. That avoids the extra (unnecessary) complexity of creating a new, dedicated, form for the task. Having said that, the separate form could also be made to work should you prefer that approach.

To link the query to the control on the form you have to reference the item as a qualification of Forms('FormName').
May 29 '09 #26
Redbeard
112 100+
Ok so I created a new form that just has an unbound text box and a button on it. When I click my keyword button on my main form it opens the new form with the unbound textbox and a button. I type my keyword in and hit the button to run my filter... no problem run fine. But when I go to use it a second time it ignores the new word I typed in and just filter again for the first word, same as before. The only way to clear it is to close the main form and open it. There must be a way around this, it is driving me mad.
May 29 '09 #27
NeoPa
32,556 Expert Mod 16PB
That's a little bit more complicated than I'd hoped. OK. The hard way (using a separate form).

Is the main form (where the filter should be applied) closed between different attempts?

If not, what is the code behind your command button (Please copy and paste)?
May 29 '09 #28
Redbeard
112 100+
Sorry for doing it the hard way but there is really no room left on my form for another text box. No the Main form is not close between attempts... that is the problem. I can make it work if I shut down the main form after every attempt but that take time. I would like to be able to filter the main form without closing it. Here is the code for the button on the new form that activates the filter.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Run_Click()
  2.  
  3. DoCmd.OpenForm "frmDescription", , "qryKeyword"
  4. Forms("frmKeyWordSearch").Refresh
  5. DoCmd.Close acForm, Me.Name
  6.  
  7. End Sub
Jun 1 '09 #29
NeoPa
32,556 Expert Mod 16PB
I'm rushing now, but try requerying the main form (I'm sorry I'm not sure which that is atm) after setting the new criteria.

I will check back later and give it some deeper thought if you haven't found this sorts your problem out.
Jun 1 '09 #30
Redbeard
112 100+
Problem Solved... thanks Neopa! The requery actually fixes my original code, here is my original code that I posted (A little bit clean up):

Expand|Select|Wrap|Line Numbers
  1. Private Sub Keyword_Search_Click() 
  2. On Error GoTo Err_Keyword_Search_Click 
  3.  
  4.     Forms("frmDescription").Refresh 
  5.     DoCmd.OpenForm "frmDescription", , "qryKeyword"  
  6.  
  7. Exit_Keyword_Search_Click: 
  8.     Exit Sub 
  9.  
  10. Err_Keyword_Search_Click: 
  11.     MsgBox Err.Description 
  12.     Resume Exit_Keyword_Search_Click 
  13.  
  14. End Sub 
And here is the new code that solved the problem without using any new forms or text boxes!

Expand|Select|Wrap|Line Numbers
  1. Private Sub Keyword_Search_Click()
  2. On Error GoTo Err_Keyword_Search_Click
  3.  
  4.     Forms!frmDescription.Requery
  5.     DoCmd.OpenForm "frmDescription", , "qryKeyword"
  6.  
  7. Exit_Keyword_Search_Click:
  8.     Exit Sub
  9.  
  10. Err_Keyword_Search_Click:
  11.     MsgBox Err.Description
  12.     Resume Exit_Keyword_Search_Click
  13.  
  14. End Sub

Thanks again!
Jun 1 '09 #31
NeoPa
32,556 Expert Mod 16PB
Nicely done RedBeard.

It's unfortunate that Refresh simply regrabs the existing records. A Requery is needed to redo the whole query. Refresh neither adds new records, nor removes deleted ones, and certainly doesn't apply any new filter.

Only M$ would know why it's called Refresh :S
Jun 1 '09 #32

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

Similar topics

3
by: Chris H | last post by:
Ok in the following code I am trying to have my keywards meta tag auto insert the top 10 titles from most recently added database entries, right now the while loop is only setting the $keyword...
25
by: samjnaa | last post by:
Please check for sanity and approve for posting at python-dev. In Visual Basic there is the keyword "with" which allows an object- name to be declared as governing the following statements. For...
3
by: Richard S | last post by:
CODE: ASP.NET with C# DATABASE: ACCES alright, im having a problem, probably a small thing, but i cant figure out, nor find it in any other post, or on the internet realy (probably cuz i wouldnt...
14
by: Simon Gare | last post by:
Hi, have a search.asp page with results.asp page drawing data from an SQL db, problem is the user has to type the whole field value into the search box to retrieve the value on results.asp, what...
1
by: qiong | last post by:
Dear friends, Good evening, I have some problems with finding keyword ":\" for each cell. My objective is to find that keyword in each cell in each worksheet which represent the link. Eg:...
2
by: rlemusic | last post by:
Hi everybody, I’m creating a database in Access (I believe it’s 2000) to catalogue items in the archives of a small museum. I’m a total n00b as far as using Access goes, but by looking at some...
2
by: godfather96 | last post by:
I am having trouble grouping using xslt 1.0 Below is a sample stylesheet and xml file. My end result would be a list of distinct "@Keyword" for a given Store and the sum of their "@Count" ...
3
by: Paul | last post by:
Hello, I'm having a CSS positioning problem and hope someone can help me out please? If you take a look at this test page: http://www.greenflagaward.org.uk/home/beta In Safari 3.0 and...
10
by: marting | last post by:
Before I throw my new expensive laptop out of the window! I'm stuck on getting my joins right with the correct amount in a column count. After speaking with someone a few weeks back, they...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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.