Page 1 of 1
Working with Microsoft Access
Posted: Thu Sep 21, 2006 6:34 pm
by Rick Lipkin
To All
I have done searches in this forum for working with MS Access .. I have found topics on ODBC and ADO .. and searched on both with not much success.
If anyone has some snippits of code connecting to a .mdb ... a simple browse, inserting and editing a record .. I would be very grateful.
Thanks
Rick Lipkin
SC Dept of Health
Re: Working with Microsoft Access
Posted: Thu Sep 21, 2006 8:06 pm
by Enrico Maria Giordano
This is a sample of how to browse a MDB:
Code: Select all
#include "Fivewin.ch"
#include "Tcbrowse.ch"
FUNCTION MAIN()
LOCAL oRs, oErr
oRs = CREATEOBJECT( "ADODB.Recordset" )
TRY
oRS:Open( "SELECT * FROM Clienti", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=clienti.mdb", 1, 3 )
CATCH oErr
? oErr:Description
RETURN NIL
END TRY
WBROWSERECORDSET( oRs )
TCBROWSERECORDSET( oRs )
oRs:Close()
RETURN NIL
STATIC FUNCTION WBROWSERECORDSET( oRs )
LOCAL oDlg, oBrw, nRec
DEFINE DIALOG oDlg SIZE 300, 300
@ 0, 0 LISTBOX oBrw FIELDS oRs:Fields( "Cliente" ):Value;
HEADERS "CLIENTI";
ON RIGHT CLICK ( nRec := oRs:AbsolutePosition,;
oBrw:Report( "TWBrowse report", .T. ),;
oRs:MoveFirst(),;
oRs:Move( nRec - 1 ) )
oBrw:bLogicLen = { || oRs:RecordCount }
oBrw:bGoTop = { || oRs:MoveFirst() }
oBrw:bGoBottom = { || oRs:MoveLast() }
oBrw:bSkip = { | nSkip | Skipper( oRs, nSkip ) }
oBrw:cAlias = "ARRAY"
ACTIVATE DIALOG oDlg;
ON INIT oDlg:SetControl( oBrw );
CENTER
RETURN NIL
STATIC FUNCTION TCBROWSERECORDSET( oRs )
LOCAL oDlg, oBrw, oCol, nRec
DEFINE DIALOG oDlg SIZE 300, 300
@ 0, 0 BROWSE oBrw;
ON RIGHT CLICK ( nRec := oRs:AbsolutePosition,;
oBrw:Report( "TWBrowse report", .T. ),;
oRs:MoveFirst(),;
oRs:Move( nRec - 1 ) )
ADD COLUMN TO oBrw;
DATA oRs:Fields( "Cliente" ):Value;
HEADER "CLIENTI"
oBrw:lCellStyle = .T.
oBrw:bLogicLen = { || oRs:RecordCount }
oBrw:bGoTop = { || oRs:MoveFirst() }
oBrw:bGoBottom = { || oRs:MoveLast() }
oBrw:bSkip = { | nSkip | Skipper( oRs, nSkip ) }
oBrw:cAlias = "ARRAY"
ACTIVATE DIALOG oDlg;
ON INIT oDlg:SetControl( oBrw );
CENTER
RETURN NIL
STATIC FUNCTION SKIPPER( oRs, nSkip )
LOCAL nRec := oRs:AbsolutePosition
oRs:Move( nSkip )
IF oRs:EOF; oRs:MoveLast(); ENDIF
IF oRs:BOF; oRs:MoveFirst(); ENDIF
RETURN oRs:AbsolutePosition - nRec
EMG
Posted: Thu Sep 21, 2006 9:23 pm
by Rick Lipkin
Enrico
Thank you ... I saw bits and pieces of this code but not all together .. VERY much appreciate your quick responce.
Rick Lipkin