CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: DAO help

  1. #1
    Guest

    DAO help

    Hi,

    I´d like to open an Access Database throught DAO in VB. If I declare a Database in Visual Basic, dim db as Database, the compiler generates a warning, because the Object couldn´t be found. (also not in the Object Catalog) How can I set up VB in order to use DAO?
    Also, I just have to read a recordset from a table. Should I use a snapshot (I dpn´t have to modify a record, just sort them)? Where can I get some really basic VB Code on this Subjet?



    thanks, Sebastian




  2. #2
    Join Date
    Jan 2000
    Location
    MO, USA
    Posts
    1,506

    Re: DAO help

    First you have to set a reference to the Microsoft DAO 3.51 Object Library (the version depends on your system 2.5 through 4.0) by going to the Project Menu then References. Then you can do the following:

    private Sub Form_Load()
    Dim db as Database
    Dim rs as Recordset
    dim sql as string

    set db = Opendatabase("C:\Program Files\Microsoft Visual Studio\VB98\biblio.mdb")

    sql = "SELECT * FROM Authors"

    set rs = db.openrecordset(sql, dbOpenSnapShot)

    MsgBox rs.Fields(1)

    rs.close
    End Sub




    Hope this helps,
    John

    John Pirkey
    MCSD
    www.ShallowWaterSystems.com
    John Pirkey
    MCSD (VB6)
    http://www.stlvbug.org

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured