Ahsan Amin


I am trying to compate a textbox value with field value and using found() function to check if found or not. I am entering the same value as it is in a table field but found() function returns false. I am using the following code:

LOCATE FOR ALLTRIM(SubName) == 'thisform.txtSubName.Value'
IF FOUND()
MESSAGEBOX("This subject already exists")
RETURN
ENDIF




Re: Locate Command

dni


You may try (check for upper and lowercase):

Code Snippet

LOCATE FOR ALLTRIM(SubName) = thisform.txtSubName.Value

IF FOUND() = .T.

MESSAGEBOX("....")

RETURN .F. && OR RETURN TO MASTER

ENDIF







Re: Locate Command

Alex Feldstein

If you want to check for any case:

LOCATE FOR LOWER(ALLTRIM(subname)) = LOWER(ALLTRIM(thisform.txtsubname.value))

Note the absence of quotes per your message.






Re: Locate Command

Naomi Nosonovsky

If you have an index on SubName and know the subname's field length, the following would be better:

Code Snippet

select myTable

locate for SubName = padr(thisform.txtSubName.value,20) && Assuming 20 is the field length, put the actual number instead

if found()

***

endif





Re: Locate Command

Alex Feldstein

Naomi's choice would be better because it is optimizable, which is faster.

An example of index with Alltrim() was provided as it is what you were using.





Re: Locate Command

Fox Me Up

set exact off

Locate For ALLT(UPPER(SubName)) = ALLT(UPPER(Thisform.txtSubName.Value))

IF Found()

return Messagbeox("Already Exists")

ENDIFd