Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Ken Murphy
  Where is Ken Murphy?
 Springhill
 Canada
 Ken Murphy
 To: FRED QUAYE
  Where is FRED QUAYE?
 
 Ghana
 FRED QUAYE
 Tags
Subject: RE: Seek Function behaving strangely
Thread ID: 104663 Message ID: 104668 # Views: 1 # Ratings: 1
Version: Visual FoxPro 6 Category: Errors & Debugging
Date: Friday, August 18, 2006 8:57:07 PM         
   


> This is really strange. I have a text box , with recordsoure = None.
>
> If a user inputs data there is a routine which checks as to whether that
> code exists. Surely to check for duplicates, however the search results for duplicates is just not working.
>
> The search routine I've placed in the lostfocus of the text box
>
> Use result order res_code
> seek alltrim(thisform.text1.value)
>
>
if found()

> Message ............duplicate record found
>
>
else

>
>
>
endif

>
>
> If I put in a duplicate, it just ignores the test routine in the text b
> ox.
>
> Wkat I'm I doing wrong? This is a very simple search, so I'm even amazed
> at the outcome


Further to what Brad gave you, there are a number of things that might improve your code.

1 - begin with the textbox. Take a look at the field definition for Result.Res_Code. If this is a ten byte alpha field, then make sure that the user enters a ten byte alpha value by using the InputMask. For example, you might want to use an input mask of "XXXXXXXXXX" or if you want the alphas to be capitalized, you might want to use "!!!!!!!!!!". You can also play with a combination of the inputmask and the format. Now, get rid of the ALLTRIM() in your seek. As long as the input mask and field are the same type and length, your users will have input a matchable value.

2 - use the alias and tag in the SEEK() function. For example:
SEEK(This.Value,[Result1],[ResCode])
Note that I use an alias of "Result1" rather than "Result." If you are using the SEEK() function, you are moving the record pointer. If your user is working on the Result table, that means that you are moving the record pointer on your user - not good. You can avoid this by opening another instance of your table. Drop that same table on your form's D/E again and then change the alias to Result1 or do it programmatically in the D/E's .OpenTables() method using
USE Result IN 0 SHARED AGAIN ALIAS Result1
Now you can do a SEEK() over Result1 and leave Result's record pointer where it is.

3 - use the INDEXSEEK() function rather than the SEEK() function. You could therefore
INDEXSEEK(This.Value,.f.,[Result],[ResCode])
and VFP will only search the index - the record pointer will not move. This is preferable to using a second instance of the table because you do not have the overhead of loading that table again.

4 - as Brad says, you should probably put this code in the .Valid() of the textbox. Obviously, you do not want the user to enter a duplicate value. If this is the case, make sure that the user cannot leave the textbox until he/she enters a valid value. To do this, you use the return value. For example,
***  MyTextBox.Valid   ***

LOCAL lnRetVal 

IF NOT EMPTY(ALLTRIM(This.Value))
   IF NOT INDEXSEEK(This.Value,.f.,[Result],[ResCode])
      lnRetVal = 1
   ELSE
      lnRetVal = 0
      MESSAGEBOX([Duplicate Result Code])
   ENDIF
ELSE
   && No value has been entered - allow the user to gracefully exit the form by placing focus in the previous control
   lnRetVal = -1
ENDIF
RETURN lnRetVal

By returning a numeric value from the .Valid() you can move focus. If the value is positive, focus will move that many steps in the tab order. In this case, when lnRetVal = 1, focus will move to the next control. If the value is negative it works the same way, but it moves to previous controls in the tab order. In this case, when lnRetVal = -1, it moves to the previous control. Most importantly, when lnRetVal = 0, focus does not shift. The user will not be able to leave that textbox until he/she empties the textbox or enters a valid result code.

Ken
You shall know the truth - and the truth shall set you free. (John 8:33)

ENTIRE THREAD

Seek Function behaving strangely Posted by FRED QUAYE @ 8/18/2006 8:16:34 PM
RE: Seek Function behaving strangely Posted by Borislav Borissov @ 8/18/2006 8:19:51 PM
RE: Seek Function behaving strangely Posted by Brad Schulz @ 8/18/2006 8:26:18 PM
RE: Seek Function behaving strangely Posted by Ken Murphy @ 8/18/2006 8:57:07 PM