I have a xBrowse list box already established .. I have a change motorpool option that worked fine under fwh txbrowse ..
What happends is the record set is completely changed because the dataset is closed and re-opened with a new set of values .. did not have a problem pryor to migrating my listbox to xbrowse..
Here is the jist of the code :
- Code: Select all Expand view
xTITLE := "TRIPS Records Browse for Agency\Motorpool "+ALLTRIM(xAGENCY)+"\"+ALLTRIM(xPOOL)
nWd := GetSysMetrics(0) * .79
nHt := GetSysMetrics(1) * .8
DEFINE ICON oICO RESOURCE "KEY1"
DEFINE WINDOW oEMP ;
FROM 10,10 to nHt, nWd PIXEL ;
of oWndMDI ;
TITLE xTITLE ;
MENU BuildMenu( cTYPE ) ;
ICON oICO ;
NOMINIMIZE ;
NOZOOM ;
MDICHILD
@ 0, 0 xBROWSE oBrw of oEmp ;
RECORDSET oRsTrip ;
COLUMNS ;
'DATE', ;
'DATE_BACK', ;
'LNAME', ;
'FNAME', ;
'VNUMBER', ;
'LICENSE', ;
'STARTMILES', ;
'ENDMILES', ;
'DESTINAT', ;
'PROGNAME', ;
'AGENCY', ;
'MTRPOOL' ;
COLSIZES 80,80,100,100,50,70,70,70,180,150,50,50 ;
HEADERS "Date", ;
"Returned", ;
"Lname", ;
"Fname", ;
"Vnumb", ;
"License", ;
"Start", ;
"End", ;
"Destination", ;
"Program", ;
"Agency", ;
"Mtrpool" ;
AUTOSORT AUTOCOLS LINES CELL
oEmp:oClient := oBrw
oBrw:CreateFromCode() // recommendation from daniel
oBrw:bLDblClick := { |nRow,nCol | _tripview( "V", "","",oRsTrip ) }
ACTIVATE WINDOW oEMP ;
ON INIT( oBrw:SetFocus(), .F. ) ;
VALID ( IIF( !lOK2, _TripClose(.T., oRsTrip, oBar1), .F. ))
RETURN( .T. )
Change motorpool code errors when I try to reopen the new recordset :
- Code: Select all Expand view
//-----------------------
Static Func _Chgmtrpool() // oRsTrip )
LOCAL SAYING,oDLG,oLBX, oRsPool, cSQL, oERR
LOCAL cTITLE, lOK, cSAY, oSAY
SysReFresh()
IF xADMIN = 'Y' .or. xMGR = 'Y' .or. xSUPER = 'Y'
ELSE
SAYING := "Sorry .. your do not have rights to look at other MotorPools"
MsgInfo( saying )
RETURN(.F.)
ENDIF
oRsPool := TOleAuto():New( "ADODB.Recordset" )
oRsPool:CursorType := 1 // opendkeyset
oRsPool:CursorLocation := 3 // local cache
oRsPool:LockType := 3 // lockoportunistic
DO CASE
CASE (xSUPER = 'Y' .or. xADMIN = 'Y')
cSQL := "SELECT * from MTRPOOL where ageneid = '"+xAGENEID+"' order by mtrpool"
cTITLE := "ALL Motorpool for Agency "+xAGENCY
CASE xMGR = 'Y'
cSQL := "SELECT * from MPOOLOC where ageneid = '"+xAGENEID+"' and userid = '"+xLOGIN+"' order by mtrpool"
cTITLE := "SELECTed Motorpools for Agency "+alltrim(xAGENCY)+"\"+xLOGIN
OTHERWISE
SAYING := "SORRY ... you do not have rights to see other MotorPools"
MsgInfo( saying )
RETURN(.F.)
ENDCASE
TRY
oRSPool:Open(cSQL,'Provider='+xPROVIDER+';Data Source='+xSOURCE+';Initial Catalog='+xCATALOG+';User Id='+xUSERID+';Password='+xPASSWORD )
CATCH oErr
DO CASE
CASE (xSUPER = 'Y' .or. xADMIN = 'Y')
MsgInfo( "Error in Opening MTRPOOL table" )
CASE xMGR = 'Y'
MsgInfo( "Error in Opening MPOOLOC table" )
ENDCASE
RETURN(.F.)
END TRY
IF oRsPool:eof
SAYING := "Sorry ... there are no Motorpools found"
MsgAlert( SAYING )
oRsPool:Close()
RETURN(.F.)
ENDIF
lOK := .F.
oRsPool:MoveFirst()
DEFINE DIALOG oDlg ;
FROM 2, 45 to 18, 89 ;
COLOR "W+/W" ;
TITLE cTITLE ;
STYLE nOr( WS_POPUP,WS_CAPTION,WS_THICKFRAME )
@ 0.5, 0.5 LISTBOX oLBX FIELDS ;
oRsPool:Fields("mtrpool"):Value ;
HEADERS "Motorpool" ;
SIZE 165,100 ;
SIZES 120 ;
of oDlg ;
UPDATE
@ 6,3 BUTTON "&Ok" ;
SIZE 25,10 of oDLG ;
ACTION ( xPOOLID := oRsPool:Fields("poolid"):Value, ;
xPOOL := oRsPool:Fields("mtrpool"):Value,;
lOK := .T., ;
oDlg:END() ) ;
DEFAULT
@ 6,8 BUTTON "&Cancel" ;
SIZE 25,10 of oDLG ;
ACTION ( oDlg:END(), lOK := .F. )
oLbx:bLogicLen := { || oRsPool:RecordCount }
oLbx:bGoTop := { || oRsPool:MoveFirst() }
oLbx:bGoBottom := { || oRsPool:MoveLast() }
oLbx:bSkip := { | nSkip | Skipper( oRsPool, nSkip ) }
oLbx:cAlias := "ARRAY1"
ACTIVATE DIALOG oDlg
oRsPool:CLose()
SysReFresh()
IF lOK = .F.
ELSE
oBRW:cALIAS:=NIL // this worked under txbrowse to reset the browse object
oRsTrip:CLose()
oRsTrip := nil
DEFINE DIALOG oDlg ;
FROM 5, 8 to 10, 75 ;
TITLE "Please be patient " ;
COLOR "N/W" ;
STYLE nOr( WS_POPUP,WS_CAPTION,WS_THICKFRAME )
cSAY := "Opening Initial TRIPS Data Recordset for Motorpool "+alltrim( xPOOL )
@ 1,10 SAY oSay var cSAY of oDLG COLOR "N/W"
oDLG:bStart := { | | lOK1 := _OpenUm(oDlg ) }
ACTIVATE DIALOG oDLG CENTERED
IF lOK1 = .F.
SysReFresh()
RETURN(.F.)
ENDIF
ENDIF
oEMP:ReFresh()
oBrw:ReFresh()
SysReFresh()
xTITLE := "TRIPS Records Browse for Agency\Motorpool "+ALLTRIM(xAGENCY)+"\"+ALLTRIM(xPOOL)
oEMP:cTITLE(xTITLE)
oEMP:ReFresh()
SysReFresh()
RETURN( .T. )
//----------------
Static Func _OpenUm(oDlg )
LOCAL oErr, SAYING, cSTRING, cSQL
SysReFresh()
cSQL := "SELECT * from TRIPS where AGENCY = '"+xAGENCY+"' and MTRPOOL = '"+xPOOL+"'" //order by LICENSE,DATE DESC"
oRsTRIP := TOleAuto():New( "ADODB.Recordset" )
oRsTRIP:CursorType := 1 // opendkeyset
oRsTRIP:CursorLocation := 3 // local cache
oRsTRIP:LockType := 3 // lockoportunistic
TRY
oRsTRIP:Open( cSQL,'Provider='+xPROVIDER+';Data Source='+xSOURCE+';Initial Catalog='+xCATALOG+';User Id='+xUSERID+';Password='+xPASSWORD )
CATCH oErr
MsgInfo( "Error in Opening TRIPS table" )
oDLG:END()
RETURN(.F.)
END TRY
oDlg:End()
RETURN(.T.)
Error code :
- Code: Select all Expand view
Application
===========
Path and name: C:\FOX\DHEC\VEHSQL-NEW\Veh32.Exe (32 bits)
Size: 3,510,784 bytes
Time from start: 0 hours 0 mins 56 secs
Error occurred at: 07/12/2010, 21:10:33
Error description: Error ADODB.Recordset/6 DISP_E_UNKNOWNNAME: RECORDCOUNT
Args:
Stack Calls
===========
Called from: source\rtl\win32ole.prg => TOLEAUTO:RECORDCOUNT(0)
Called from: .\source\classes\XBROWSE.PRG => (b)TXBROWSE:SETADO(3972)
Called from: .\source\classes\XBROWSE.PRG => (b)TXBROWSE:TXBROWSE(349)
Called from: => TXBROWSE:KEYCOUNT(0)
Called from: .\source\classes\XBROWSE.PRG => TXBROWSE:REFRESH(922)
Called from: .\source\classes\XBROWSE.PRG => TXBROWSE:MOUSELEAVE(3126)
Called from: .\source\classes\XBROWSE.PRG => TXBROWSE:HANDLEEVENT(10155)
Called from: .\source\classes\WINDOW.PRG => _FWH(3347)
Called from: => DIALOGBOXINDIRECT(0)
Called from: .\source\classes\DIALOG.PRG => TDIALOG:ACTIVATE(273)
Called from: .\source\function\ERRSYSW.PRG => ERRORDIALOG(343)
Called from: .\source\function\ERRSYSW.PRG => (b)ERRORSYS(27)
Called from: source\rtl\win32ole.prg => TOLEAUTO:RECORDCOUNT(0)
Called from: .\source\classes\XBROWSE.PRG => (b)TXBROWSE:SETADO(3972)
Called from: .\source\classes\XBROWSE.PRG => TXBROWSE:PAINT(1285)
Called from: .\source\classes\XBROWSE.PRG => TXBROWSE:DISPLAY(990)
Called from: .\source\classes\CONTROL.PRG => TCONTROL:HANDLEEVENT(1439)
Called from: .\source\classes\XBROWSE.PRG => TXBROWSE:HANDLEEVENT(10158)
Called from: .\source\classes\WINDOW.PRG => _FWH(3347)
Called from: => DIALOGBOXINDIRECT(0)
Called from: .\source\classes\DIALOG.PRG => TDIALOG:ACTIVATE(273)
Called from: TRIPBROW.PRG => _CHGMTRPOOL(566)
Called from: TRIPBROW.PRG => (b)BUILDMENU(290)
Called from: .\source\classes\MENU.PRG => TMENU:COMMAND(437)
Called from: .\source\classes\WINDOW.PRG => TWINDOW:COMMAND(1017)
Called from: .\source\classes\MDIFRAME.PRG => TMDIFRAME:COMMAND(243)
Called from: => TMDIFRAME:HANDLEEVENT(0)
Called from: .\source\classes\WINDOW.PRG => _FWH(3347)
Called from: => WINRUN(0)
Called from: .\source\classes\WINDOW.PRG => TMDIFRAME:ACTIVATE(966)
Called from: MAIN.PRG => MAIN(411)
The error happends in the dialog the calls the bStart OpenUM() code
There has to be a way to re-use the existing listbox and refill and refresh the data .. Any ideas ??
Rick Lipkin