field valid method

pl.help what i am doing wrong cos when i add new dl_no( my field name) it same message coming " already exists"

i want to seek dl_no in checkcust table and if found get the message and focus on same field and if not the go to next field


SELECT CHECKCUST
SET ORDER TO DL_NO && DL_NO
SEEK dl_no

IF FOUND()
=messagebox("ALREADY EXISTS")
return .F.
ELSE

ENDIF

[444 byte] By [NILKAMAL] at [2008-1-10]
# 1

If you have a field named dl_no then this code would always show the messagebox.

I don't know where you're calling this code. Here is a sample doing that with a textbox control that DOESN'T have any controlsource set:

Code Snippet

* LostFocus

local lcOldExact

lcOldExact = set("exact")

set exact on

* Uppercase if needed

if seek(padr(this.Value, fsize("dl_no","checkcust")), "checkcust", "dl_no")

nodefault

this.SetFocus()

messagebox("Already Exists")

endif

set exact &lcOldExact

CetinBasoz at 2007-10-3 > top of Msdn Tech,Visual FoxPro,Visual FoxPro General...
# 2

What kind of index is DL_NO ? Unique ?

dni at 2007-10-3 > top of Msdn Tech,Visual FoxPro,Visual FoxPro General...
# 3
yes dl_no index is unique
NILKAMAL at 2007-10-3 > top of Msdn Tech,Visual FoxPro,Visual FoxPro General...
# 4

It doesn't matter what type it's. If your index is based on a field named dl_no:

Code Snippet

seek dl_no

if found()

is equivalant to:

Code Snippet
Seek dl_no
if .T.
CetinBasoz at 2007-10-3 > top of Msdn Tech,Visual FoxPro,Visual FoxPro General...
# 5

You may try to put in valid:

IF SEEK(DL_NO)

=MESSAGEBOX("ALREADY EXISTS")

RETURN

ENDIF

dni at 2007-10-3 > top of Msdn Tech,Visual FoxPro,Visual FoxPro General...
# 6

thanks for reply

i try this but get same messge

i have table with dl_no field

now i open form , when i put value in dl_field it get message already exists ( i think it seek this value too )

thanks

NILKAMAL at 2007-10-3 > top of Msdn Tech,Visual FoxPro,Visual FoxPro General...
# 7

Yes I told you that before it would always return .T. for found if you have a field named dl_no. You can only use indexseek() on a buffered table for such an operation but as soon as you move off the record it is updated in index and always returns .t.

Maybe you're trying to do this:

Code Block

luCurrent = dl_no

lnRecno = recno()

locate for dl_no == m.luCurrent and recno() <> m.lnRecno

llExists = !eof()

go m.lnRecno

if m.llExists

messagebox("exists")

endif

CetinBasoz at 2007-10-3 > top of Msdn Tech,Visual FoxPro,Visual FoxPro General...