James Bott wrote:Nages,
The original question in the first post was how to find if a combination of two fields already exists in the table. I provided a simple and straight answer for that which works irrespective of the indexes
.
Sorry, I never meant to imply otherwise.
I was just pointing out that using primary keys solves this and many other problems Silvio has been having. When using primary keys, Silvio won't need to do this lookup. However, your technique will be useful in other situations. Thanks for providing it--I already have it in my notes file.
James
But which primaries should I use?
the clienti.dbf file has these indexes
INDEX ON UPPER(CLICOGNOME) TAG CLICOGNOME
INDEX ON UPPER(CLINOME) TAG CLINOME
INDEX ON UPPER(CLIFISCALE) TAG CLIFISCALE
INDEX ON UPPER(CLIPARTIVA) TAG CLIPARTIVA
INDEX ON UPPER(CLIINDIRIZ) TAG CLIINDIRIZ
INDEX ON UPPER(CLIPAESE) TAG CLIPAESE
INDEX ON UPPER(CLICAP) TAG CLICAP
INDEX ON UPPER(CLIPROV) TAG CLIPROV
INDEX ON UPPER(CLIREGIONE) TAG CLIREGIONE
INDEX ON UPPER(CLITELEF1) TAG CLITELEF1
INDEX ON UPPER(CLITELEF2) TAG CLITELEF2
INDEX ON UPPER(CLIEMAIL) TAG CLIEMAIL
INDEX ON UPPER(CLISITOWEB) TAG CLISITOWEB
INDEX ON UPPER(CLIAPPUNTI) TAG CLIAPPUNTI
INDEX ON DELETED() TAG DELETED
and the fields are these - Code: Select all Expand view RUN
local aFields := { { "CLICOGNOME", "C", 20, 0 },;
{ "CLINOME", "C", 20, 0 },;
{ "CLIFISCALE", "C", 16, 0 },;
{ "CLIPARTIVA", "C", 11, 0 },;
{ "CLIINDIRIZ", "C", 30, 0 },;
{ "CLIPAESE", "C", 30, 0 },;
{ "CLICAP", "C", 5, 0 },;
{ "CLIPROV", "C", 2, 0 },;
{ "CLIREGIONE", "C", 20, 0 },;
{ "CLITELEF1", "C", 14, 0 },;
{ "CLITELEF2", "C", 14, 0 },;
{ "CLIEMAIL", "C", 40, 0 },;
{ "CLISITOWEB", "C", 40, 0 },;
{ "CLIAPPUNTI", "C", 200, 0 } }
the idea of using only one field (FULLNAME) was just a test I did but in reality I need a field for the Surname and a field for the name.
There are many customers with the same surname just think that entire families go to the sea. There is the possibility of having the same surname and the same name
nages suggestion only works on the first try i.e:
1) I enter the surname and then the name for example "Vitali" "Pietro"
I only put control on the name
2) the procedure tells me that the name "Peter" already exists so I 3) deletes the contents of the get control and sets focus on the get, so the cusor is stopped on the get control of the name
3) I insert in place of "Pietro", my name "Silvio" which in reality is not in the archive, the procedure does not make me go ahead to enter the other fields and makes a error
this error
- Code: Select all Expand view RUN
Error description: Error BASE/1066 Argument error: conditional
Args:
[ 1] = U
Stack Calls
===========
Called from: test.prg => CLCLAVE( 305 )
Called from: test.prg => (b)CLEDITA( 206 )
Called from: .\source\classes\TGET.PRG => TGET:LVALID( 2282 )
is there a solution please?
I'll post the valid function I made
@ 26, 10 SAY "Nome :" OF oDlg SIZE 22, 8 PIXEL FONT oFont
@ 24, 67 GET aGet[2] VAR oCliente:Clinome OF oDlg SIZE 100, 12 PIXEL FONT oFont ;
VALID CLClave( oCliente:Clicognome, aGet[2], 1,oDbf,oCliente:Clinome )
- Code: Select all Expand view RUN
function CLClave( cCognome, oGet, nMode,oDbf,cNome )
local lreturn := .f.
local nRecno := oDbf:RecNo()
local nOrder := oDbf:OrdNumber()
local nArea := Select()
if Empty( cNome )
if nMode == 4
return .t.
else
MsgStop("E' obbligatorio questo campo.")
return .f.
endif
endif
*oDbf:SetOrder( 1 ) //CLICOGNOME
* oDbf:GoTop()
IF oDbf:LookUp( UPPER( PADR( cCognome, 20 ) + PADR( cNome, 20 ) ), ;
"UPPER(CLICOGNOME+CLINOME)", { || FOUND() } )
DO CASE
Case nMode == 1 .OR. nMode == 3 // new or duplicate
lreturn := .f.
MsgStop("Nominativo esistente.")
Case nMode == 2 // modify
if oDbf:Recno() == nRecno
lreturn := .t.
else
lreturn := .f.
MsgStop("Nominativo esistente.")
endif
Case nMode == 4 //selection dialog
lreturn := .t.
END CASE
ELSE
if nMode < 4
lreturn := .t.
else
if MsgYesNo("Nominativo inesistente. ¿ Desideri inserirlo ora? ") // on selection dialog ask to add the new record
lreturn := ClEdita( , 1, , , @cCognome )
else
lreturn := .f.
endif
endif
endif
if lreturn == .f.
oGet:cText( space(20) )
endif
oDbf:SetOrder( nOrder )
oDbf:GoTo( nRecno )
Select (nArea)
return lreturn
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com