toddsevans
Technical User
Does any one know which events cause a form's data environment to open/close?
I ran into a problem where the lostfocus event of a txtfield on form1 called a form2 and when form1's activate event fired again the form1 data environment was no longer open.
Here is the code in the lostfocus event:
* IF THIS IS THE 1ST BORROWER ON A LOAN & THE BORROWER NAME IS NOT
* THE SAME IN BOTH FILES (THEREFOR NAME IS BEING CHANGED)
IF (borrower_number = 1) AND (ALLTRIM(doc1.trust1) != ALLTRIM(borrower.trust1))
s_messagetitle = "VERIFY NAME CHANGE"
s_messagetext1 = "This will change the name on loan #" + ALLTRIM(borrower.loan_no)
s_messagetext2 = "from " + ALLTRIM(THISFORM.temp_char_var_1) + " to " + ALLTRIM(borrower.trust1)
s_messagetext3 = "Do you wish to proceed?"
l_font_control_1 = .T.
l_font_control_2 = .T.
l_showbutton1 = .T.
l_showbutton2 = .F.
l_showbutton3 = .T.
s_buttonname1 = "YES"
s_buttonname3 = "NO"
n_windowmode = 1
n_windowheight = 120
DO FORM displaymessage
* IF USER CLICKS "CANCEL"
IF l_button3
REPLACE borrower.trust1 WITH ALLTRIM(THISFORM.temp_char_var_1)
* IF USER CLICKS "OK" MAKE THE CHANGE
ELSE
REPLACE doc1.trust1 WITH ALLTRIM(borrower.trust1)
* AFTER THE CHANGE IS MADE ASK ANOTHER ?
s_messagetitle = "CHANGE LOAN NAME?"
s_messagetext1 = "Would you like to change the loan name from "
s_messagetext2 = ALLTRIM(doc1.nam_sort) + "?"
l_font_control_1 = .T.
l_font_control_2 = .T.
l_showbutton1 = .T.
l_showbutton2 = .F.
l_showbutton3 = .T.
s_buttonname1 = "YES"
s_buttonname3 = "NO"
n_windowmode = 1
n_windowheight = 120
DO FORM displaymessage
* IF USER CLICKS YES
IF l_button1
* I THINK THE NEXT COMMAND IS WHAT CAUSES THE DATA ENVIRONMENT
* TO AUTOMATICALLY CLOSE
DO FORM enternam_sort
REPLACE doc1.nam_sort WITH pc_temp_nam_sort
THISFORM.lblLoan_no.CAPTION = "Loan Number: " + ALLTRIM(macct1) + " (";
+ ALLTRIM(doc1.nam_sort) + ")"
THISFORM.REFRESH
ENDIF
ENDIF
ENDIF
I Solved the problem by changing the last IF/ENDIF to this:
IF l_button1
THISFORM.RELEASE
DO FORM enternam_sort
REPLACE doc1.nam_sort WITH pc_temp_nam_sort
DO FORM dataentry1
ENDIF
Problem solved but I assume this is going to slow things down as the environment is closed and reopened and the form is created again.
I'm curious of there is a better approach.
I ran into a problem where the lostfocus event of a txtfield on form1 called a form2 and when form1's activate event fired again the form1 data environment was no longer open.
Here is the code in the lostfocus event:
* IF THIS IS THE 1ST BORROWER ON A LOAN & THE BORROWER NAME IS NOT
* THE SAME IN BOTH FILES (THEREFOR NAME IS BEING CHANGED)
IF (borrower_number = 1) AND (ALLTRIM(doc1.trust1) != ALLTRIM(borrower.trust1))
s_messagetitle = "VERIFY NAME CHANGE"
s_messagetext1 = "This will change the name on loan #" + ALLTRIM(borrower.loan_no)
s_messagetext2 = "from " + ALLTRIM(THISFORM.temp_char_var_1) + " to " + ALLTRIM(borrower.trust1)
s_messagetext3 = "Do you wish to proceed?"
l_font_control_1 = .T.
l_font_control_2 = .T.
l_showbutton1 = .T.
l_showbutton2 = .F.
l_showbutton3 = .T.
s_buttonname1 = "YES"
s_buttonname3 = "NO"
n_windowmode = 1
n_windowheight = 120
DO FORM displaymessage
* IF USER CLICKS "CANCEL"
IF l_button3
REPLACE borrower.trust1 WITH ALLTRIM(THISFORM.temp_char_var_1)
* IF USER CLICKS "OK" MAKE THE CHANGE
ELSE
REPLACE doc1.trust1 WITH ALLTRIM(borrower.trust1)
* AFTER THE CHANGE IS MADE ASK ANOTHER ?
s_messagetitle = "CHANGE LOAN NAME?"
s_messagetext1 = "Would you like to change the loan name from "
s_messagetext2 = ALLTRIM(doc1.nam_sort) + "?"
l_font_control_1 = .T.
l_font_control_2 = .T.
l_showbutton1 = .T.
l_showbutton2 = .F.
l_showbutton3 = .T.
s_buttonname1 = "YES"
s_buttonname3 = "NO"
n_windowmode = 1
n_windowheight = 120
DO FORM displaymessage
* IF USER CLICKS YES
IF l_button1
* I THINK THE NEXT COMMAND IS WHAT CAUSES THE DATA ENVIRONMENT
* TO AUTOMATICALLY CLOSE
DO FORM enternam_sort
REPLACE doc1.nam_sort WITH pc_temp_nam_sort
THISFORM.lblLoan_no.CAPTION = "Loan Number: " + ALLTRIM(macct1) + " (";
+ ALLTRIM(doc1.nam_sort) + ")"
THISFORM.REFRESH
ENDIF
ENDIF
ENDIF
I Solved the problem by changing the last IF/ENDIF to this:
IF l_button1
THISFORM.RELEASE
DO FORM enternam_sort
REPLACE doc1.nam_sort WITH pc_temp_nam_sort
DO FORM dataentry1
ENDIF
Problem solved but I assume this is going to slow things down as the environment is closed and reopened and the form is created again.
I'm curious of there is a better approach.