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

Thread: Dao

  1. #1
    Join Date
    Jul 2002
    Posts
    38

    Dao

    How can I use DAO code to open a database with a password, as well as setting it's recordset?

    I don't wanna create a Data Control whenever I wanna do something like that.

    Please help.

    Thanks.

    Woobi

  2. #2
    Join Date
    Oct 2001
    Location
    India
    Posts
    52
    Try to use the .openrecordset()


    e.g.



    Dim QdfSir As QueryDef
    Dim RecoMSir As Recordset

    'gstrConn is the connect string


    With QdfSir
    .Connect = gstrConn
    .SQL = "Select A.*,B.Sir_Gen_Date From Sir_Items A,Sir B where a.Sir_Code+a.Fin_Suffix=B.Sir_Code+B.Fin_Suffix and B.Sir_Code>='" & TxtFSirNo.Text & "' And B.Sir_Code <= '" & TxtTSirNo.Text & "' And B.Fin_Suffix = '" & TxtFSuffix.Text & "'" & StrSql

    Set RecoMSir = .OpenRecordset()

  3. #3
    Join Date
    Jul 2002
    Posts
    38
    So what do I put as the connect string?

  4. #4
    Join Date
    Oct 2001
    Location
    India
    Posts
    52
    Something like this

    gstrConn = "odbc;dsn=" & Trim(gstrDsn) & ";uid=" & Trim(gstrUser) & ";pwd=" & strpw & ";database=" & gstrDb & ";"

  5. #5
    Join Date
    Jul 2002
    Posts
    38
    Does that mean whenever I try to create a new querydef, I have to reconnect to the database all the time? But what if it's a single user database? That wouldn't cause the program to go haywire?

    I thought the database can only be opened once and during the program?

  6. #6
    Join Date
    Jan 2001
    Posts
    22
    Using DAO to get into an Access database?

    Set reference in project to MS DAO 3.6 Object Library.

    ------------------------------------------------------------------
    Dim DB1 as DAO.database
    Dim RS1 as DAO.Recordset
    Dim ssql as string
    Dim pathstringvariable as string
    Dim passwordstringvariable as string

    pathstringvariable = "C:\MyProjectFolder\SuperDatabase.mdb"
    passwordstringvariable="Theshadowknows"


    Set DB1 = DAO.opendatabase(Pathstringvariable, false, false, ";pwd=" & passwordstringvariable)

    ssql = "SELECT * FROM Table1"

    set rs1 = db1.openrecordset(ssql,dbopensnapshot)
    ------------------------------------------------------------------


    Like that.


    Hope That helps.
    -Jpicasso


    P.S. Stay as far away from data controls as possible.

  7. #7
    Join Date
    Jul 2002
    Posts
    38
    Thanks JPicasso_00, that is exactly what i was looking for. Thanks. =)

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