Working with Microsoft Access

Post Reply
User avatar
Rick Lipkin
Posts: 2397
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Working with Microsoft Access

Post 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
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: Working with Microsoft Access

Post 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
User avatar
Rick Lipkin
Posts: 2397
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Post 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
Post Reply