Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What Event Opens A Data Environtment?

Status
Not open for further replies.

toddsevans

Technical User
Aug 20, 2004
19
US
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.
 
HI

It is likely that you have a default data session in form enternam_sort and on that forms close or release, you are releasing the open tables. Otherwise I do not find a reason for the open tables getting lost.

Another possibility is that the default data session is reset in the second form by your code and you are not getting back to the first forms data session.

You can make the enternam_sort form private and try.

However, you have solved your problem and so this is only for your satisfaction to know what is what and understand the situation. :)

____________________________________________
ramani - (Subramanian.G) :)
 
in enternam_sort make sure that either:

The datasession property is set to default and you don't have any of the same tables in that DE that you have in form1's DE

...or...

that the datasession property is set to private

boyd.gif

 
Thanks for the advice.

I looked at enternam_sort's data environment and it contains no tables. All this form does is store a user input character string to a variable.

The first form does use a private DE and enternam_sort was using the default DE. So...

Just for the heck of it I changed the DE to private and went back to the old code. I got the same error as before. So I put the alterted code back in and left DE private. This works but I'd love to know what is happening so I can avoid it in the future.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top