You are here:

FoxPro/problem in editing...

Advertisement


Question
QUESTION: Good day sir! this is AJ again..
I am using  vfp 9.0
I have another problem in my form sir.
When I click the edit button, then edit the details then click ok for saving, the messagebox for the duration validation appears even if I didn't edit the duration dates.
Can you explain to me the possible solution for this.
Thank you very much!

ANSWER: Hi, AJ...

Unfortunately, I don't know enough about your form to know what is causing the issue.    

I'm sure I could help you if I had your form, but this forum does not allow the upload
and/or download of files (except images).  A screen capture of the form might help, but
without the code behind the objects, it would be a long-shot at best.

If you want more definitive help, post a PRIVATE follow-up question which includes your
email address.  I will use that address to send an email to you.  Then, you can reply
directly to my email and attach your form (SCX and SCT files).  Once I open your form
and actually look at all components, I should be able to help.  

If you decide to do this, be sure you make the follow-up question PRIVATE to avoid
public disclosure of your email address.

Fred
**** THE FOLLOWING LINES ARE AN AUTOMATIC SIGNATURE FOR MY ANSWERS ****

---------- FOLLOW-UP ----------

editmode3
editmode3  

editmode2
editmode2  
QUESTION: these are the codes from my form: saveaccount; validation; cmdok.Click

(saveaccount)

WAIT WINDOW "Saving data! Please wait....." NOWAIT

cCrewno = ALLTRIM(thisform.txtCrewNo.Value)
cLname = ALLTRIM(thisform.txtLN.Value)
cFname = ALLTRIM(thisform.txtFN.Value)
cMname = ALLTRIM(thisform.txtMN.Value)
cCrewname = ALLTRIM(cLname + ", " + cFname + " " + cMname)
cRank = ALLTRIM(thisform.txtRank.Value)
cVessel = ALLTRIM(thisform.txtVessel.Value)
cRemarks = ALLTRIM(thisform.txtRemarks.Value)
cStat = ALLTRIM(thisform.cmbStatus.Value)
cVcode = ALLTRIM(thisform.txtVcode.Value)
dDated = thisform.txtDate.Value
dDtfrom = thisform.txtFrom.Value
dDtto = thisform.txtTo.Value
iRcode = thisform.txtRcode.Value
iCont = thisform.txtBond.Value

SELECT tbl_position
cArank = PADL(tbl_position.arrangeme,4,'0')

IF VAL(thisform.Tag) = 0         && add crew
nIntcode = 0
SELECT tbl_autonum
SET ORDER TO TAG intcode
IF SEEK('CACT')
  DO WHILE .t.
     IF RLOCK()
     nIntcode = tbl_autonum.autonum + 1
     REPLACE tbl_autonum.autonum WITH nIntcode
     UNLOCK IN tbl_autonum
     EXIT
     ENDIF
  ENDDO
ELSE
INSERT INTO tbl_autonum (intcode, autonum, descript) VALUES ('CACT', 1, 'For Crew Accountability Use')   
ENDIF
cVar = PADL(nIntcode,10,'0')
  
INSERT INTO tbl_crewaccount(intcode, crew_no, encodedate, crewname, last_name, first_name, mid_name, crewrank, vesname, due_from, due_to, aremark, accstat, encodedby, pos_code, vescode, arrangeme, contbond) VALUES;
(cVar, cCrewno, dDated, cCrewname, cLname, cFname, cMname, cRank, cVessel, dDtfrom, dDtto, cRemarks, cStat, cUsername, iRcode, cVcode, cArank, iCont)
  
INSERT INTO tmp_crewacct(intcode,crew_no, encodedate, crewname, last_name, first_name, mid_name, crewrank, vesname, due_from, due_to, aremark, accstat, encodedby, pos_code, vescode, arrangeme, contbond) VALUES;
(cVar, cCrewno, dDated, cCrewname, cLname, cFname, cMname, cRank, cVessel, dDtfrom, dDtto, cRemarks, cStat, cUsername, iRcode, cVcode, cArank, iCont)
  
ELSE          &&editcrew

SELECT tmp_crewacct
REPLACE tmp_crewacct.crew_no WITH cCrewno, tmp_crewacct.crewname WITH cCrewname,;
tmp_crewacct.crewrank WITH cRank, tmp_crewacct.vesname WITH cVessel,;
tmp_crewacct.last_name WITH cLname, tmp_crewacct.first_name WITH cFname,;
tmp_crewacct.mid_name WITH cMname, tmp_crewacct.aremark WITH cRemarks,;
tmp_crewacct.accstat WITH cStat, tmp_crewacct.encodedate WITH dDated,;
tmp_crewacct.due_from WITH dDtfrom, tmp_crewacct.due_to WITH dDtto,;   tmp_crewacct.editedby WITH cUsername, tmp_crewacct.editdate WITH DATETIME(),;
tmp_crewacct.pos_code WITH iRcode, tmp_crewacct.vescode WITH cVcode,;
tmp_crewacct.arrangeme WITH cArank, tmp_crewacct.contbond WITH iCont
        
  
SELECT tbl_crewaccount
SET ORDER TO Tag intcode
IF SEEK(ALLTRIM(tmp_crewacct.intcode))
  DO WHILE .t.
     IF RLOCK()
         REPLACE tbl_crewaccount.crew_no WITH cCrewno, tbl_crewaccount.encodedate WITH dDated,;
tbl_crewaccount.last_name WITH cLname, tbl_crewaccount.first_name WITH cFname,;
tbl_crewaccount.mid_name WITH cMname, tbl_crewaccount.crewname WITH cCrewname,;
tbl_crewaccount.crewrank WITH cRank, tbl_crewaccount.vesname WITH cVessel,;
tbl_crewaccount.due_from WITH dDtfrom, tbl_crewaccount.due_to WITH dDtto,;
tbl_crewaccount.aremark WITH cRemarks, tbl_crewaccount.accstat WITH cStat,;
tbl_crewaccount.editedby WITH cUsername, tbl_crewaccount.editdate WITH DATETIME(),;
tbl_crewaccount.pos_code WITH iRcode, tbl_crewaccount.vescode WITH cVcode,;
tbl_crewaccount.arrangeme WITH cArank, tbl_crewaccount.contbond WITH iCont
UNLOCK IN tbl_crewaccount
EXIT
ENDIF
ENDDO
ENDIF
ENDIF


******************************************************************

(validation)

thisform.txtFrom.Tag = 'N'
SELECT tbl_crewaccount
dFrom = tbl_crewaccount.due_from
dTo = tbl_crewaccount.due_to
SET ORDER TO TAG crew_no
IF SEEK(ALLTRIM(thisform.txtCrewNo.Value))
DO WHILE allt(tbl_crewaccount.crew_no) == allt(thisform.txtCrewNo.Value)
IF thisform.txtFrom.Value >= tbl_crewaccount.due_from AND thisform.txtFrom.Value <= tbl_crewaccount.due_to
thisform.txtFrom.Tag = 'Y'
MESSAGEBOX("Crew has an existing accountability from "+DTOC(dFrom) +" to " +DTOC(dTo) +".", 0+16, "User Message")
EXIT
ENDIF
IF thisform.txtTo.Value >= tbl_crewaccount.due_from AND thisform.txtTo.Value <= tbl_crewaccount.due_to
thisform.txtFrom.Tag = 'Y'
MESSAGEBOX("Crew has an existing accountability from "+DTOC(dFrom) +" to " +DTOC(dTo) +".", 0+16, "User Message")
EXIT
ENDIF
SELECT tbl_crewaccount
SKIP
ENDDO
ENDIF
thisform.Refresh


****************************************************************
cmdOk (Click)

IF LEN(ALLTRIM(thisform.txtCrewNo.Value)) = 0
MESSAGEBOX("Input Crew Number to continue.", 0+16,"User Message")
thisform.txtCrewNo.SetFocus
RETURN 0
ENDIF

IF LEN(ALLTRIM(thisform.txtLN.Value)) = 0
MESSAGEBOX("Input Crew Last Name to continue.", 0+16,"User Message")
thisform.txtLN.SetFocus
RETURN 0
ENDIF

IF LEN(ALLTRIM(thisform.txtFN.Value)) = 0
MESSAGEBOX("Input Crew First Name to continue.", 0+16,"User Message")
thisform.txtFN.SetFocus
RETURN 0
ENDIF
  
IF LEN(ALLTRIM(thisform.txtMN.Value)) = 0
MESSAGEBOX("Input Crew Middle Name to continue.", 0+16,"User Message")
thisform.txtMN.SetFocus
RETURN 0
ENDIF

IF LEN(ALLTRIM(thisform.txtRank.Value)) = 0
MESSAGEBOX("Input Crew Rank to continue.", 0+16,"User Message")
thisform.txtRank.SetFocus
RETURN 0
ENDIF

IF LEN(ALLTRIM(thisform.txtVessel.Value)) = 0
MESSAGEBOX("Input Vessel to continue.", 0+16,"User Message")
thisform.txtVessel.SetFocus
RETURN 0
ENDIF

IF EMPTY(thisform.txtBond.Value)
MESSAGEBOX("Input Contract Bond to continue.", 0+16,"User Message")
THISFORM.txtBond.SetFocus
RETURN 0
ENDIF

IF EMPTY(thisform.txtFrom.Value)
MESSAGEBOX("Input Duration to continue.", 0+16,"User Message")
THISFORM.txtFrom.SetFocus
RETURN 0
ENDIF

IF EMPTY(thisform.txtTo.Value)
MESSAGEBOX("Input Duration to continue.", 0+16,"User Message")
thisform.txtTo.SetFocus
RETURN 0
ENDIF

IF LEN(ALLTRIM(thisform.cmbStatus.Value)) = 0
MESSAGEBOX("Select Status to continue.", 0+16,"User Message")
thisform.cmbStatus.SetFocus
RETURN 0
ENDIF

thisform.validation
IF thisform.txtFrom.Tag = 'Y'
thisform.txtFrom.SetFocus
RETURN 0
ENDIF


IF MESSAGEBOX("Save data now?",4+32+256,"Confirmation") = 6
thisform.saveaccount
SET ORDER TO 2 IN tmp_crewacct ASCENDING
IF VAL(thisform.Tag) = 0
  n_account = n_account + 1
  thisform.cleartextvalue
  thisform.txtCrewNo.SetFocus
  thisform.cmdOk.Enabled = .f.
  thisform.Refresh
ELSE
  thisform.Release
ENDIF
IF VAL(thisform.Tag) = 1
  thisform.cmdPrint.Click
ENDIF
ENDIF

**********************************************************************

Answer
AJ,

  In the CmdOk.click event:

   thisform.validation is executed for ADD and EDIT (whether the values change or not).  To prevent it when EDITing, you can compare the existing table values to the new form values and only perform the validation step if changed.

  I think thisform.tag will tell you if it is ADD or EDIT.  If it's EDIT, compare the form.object.value to the existing table.field for the record being edited.  The validation should run only if either one is different.  I haven't researched the code enough to give you the exact code, but I'm sure you won't have any problem knowing what to do next.

FoxPro

All Answers


Answers by Expert:


Ask Experts

Volunteer


Fred Frase

Expertise

Questions about development only. No installation or hardware specific questions, please. Your first step in requesting assistance should be to identify the version of FoxPro you are using. I can write short functions but, PLEASE do not ask me to write programs for you.

Experience

Nearly 30 years professional programming experience using FoxPro (FoxBase through VFP 9) or other xbase language, primarily in Windows environments.

Education/Credentials
Completed a 1,000 hour diploma course in programming at International Academy of Ohio (subsequently merged with Southern Ohio College).

©2016 About.com. All rights reserved.