I agree with Mike - more information please. However, I've found that unexpected tables being open are usually due to forms, classes or reports that have code that opens them and then doesn't close them - either on purpose or due to "crashes" during testing.
DO CASE
********************************************************************************************************************
CASE .lCOM
********************************************************************************************************************
** retrieve the indicated record via SPT
LOCAL lcSQL, lnConnectionHandle
IF .lMaintainConnection
lnConnectionHandle = .nConnectionHandle
ELSE
LOCAL lcConnectionInfo
lcConnectionInfo = .cConnectionInfo
lnConnectionHandle = SQLCONNECT(&lcConnectionInfo)
ENDIF
llSuccess = SQLEXEC(.nConnectionHandle,lcSQL,.cAlias)>0
IF llSuccess
** populate the tuData parameter, passed here by reference with the XML
CURSORTOXML(.cAlias,"tuData",1,8)
USE IN (.cAlias)
ENDIF
IF !.lMaintainConnection
** disconnect
SQLDISCONNECT(lnConnectionHandle)
ENDIF
IF !llSuccess
**
** CURSORTOXML does basically nothing if ther
** are no records
**
tuData = .cXMLBlankRecord
ENDIF
*********************************************************************************************************************
OTHERWISE
*********************************************************************************************************************
** retrieve the indicated record via SPT
LOCAL lcSQL, llNoData
llNoData = VARTYPE(tuPK) = "C" AND !ISNULL(tuPK) ;
and UPPER(ALLTRIM(tuPK)) == "~NODATA~"
IF USED(.cAlias)
SELECT (.cAlias)
IF "2" $ GETFLDSTATE(-1)
llChanges = .T.
ELSE
llChanges = .F.
ENDIF
ENDIF
IF !llChanges && no uncommitted changes
llSuccess = SQLEXEC(.nConnectionHandle,lcSQL,.cAlias)>0
** turn the SPT cursor 'into a remote view' to make updates
** easier in THIS.Save()
IF USED(.cAlias)
.TurnSPTCursorIntoRemoteView()
ENDIF
ELSE
llSuccess = .F.
ENDIF
ENDCASE
ENDWITH
RETURN llSuccess
And I am using two forms, one with a list ("parent" form) and other with the details ("child".
In "Child" form I do this :
**********************************************************
LOCAL lcCursorname, llSuccess, lcViewname
lcCursorname = this.bcEmployee.listcursor
lcViewname = this.bcEmployee.cAlias
llSuccess = .T.
TRY
IF USED(lcCursorname)
IF (&lcCursorname..pointer <> thisform.nPointerReq) or;
(!ISNULL(&lcCursorname..pointer) AND ISNULL(thisform.nPointerReq)) or ;
(ISNULL(&lcCursorname..pointer) AND !ISNULL(thisform.nPointerReq))
IF thisform.Validated
m.p_persoon = &lcCursorname..pointer
IF USED(lcViewname)
SELECT (lcViewname)
IF "2" $ GETFLDSTATE(-1)
thisform.setchanged()
thisform.save()
ENDIF
ENDIF
thisform.nPointerReq = m.p_persoon
thisform.Caption = "Personeelsfiche - "+TRANSFORM(viewEmployee.prsnickname)
ENDIF
ENDIF
ENDIF
CATCH TO loException
**error
DO errorhandler WITH loException.ErrorNo, PROGRAM(), loException.Lineno
ENDTRY
RETURN llSuccess
***********************************************************
Note: first I have a ~NODATA~ fetch so that the form already knows the structure of the cursor. Otherwise, data bindings will not work.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.