Results 1 to 2 of 2

Thread: openingdatabase using ADO

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2005
    Posts
    30

    openingdatabase using ADO

    hi,
    when i try to run this code i get an error that says that "the database has been placed in a state by the user that does not allow it to be opened or locked."

    what am i doing wrong? its my first time using ADO and i cant get pass this stage.

    VB Code:
    1. Private Sub Command116_Click()
    2.    Dim CurConn As New ADODB.Connection
    3. Dim rst As New ADODB.Recordset, rstCln As New ADODB.Recordset
    4. Dim CurDB As Database
    5. Set CurDB = CurrentDb
    6. Set CurConn = New ADODB.Connection
    7. With CurConn
    8. .Provider = "Microsoft.Jet.OLEDB.4.0"
    9. .ConnectionString = "data source= " & CurDB.Name
    10. .Open
    11. End With
    12.   Set rst = New ADODB.Recordset
    13. rst.CursorType = adOpenKeyset
    14. rst.LockType = adLockOptimistic
    15. rst.Open "SELECT * FROM equips WHERE [Village name] = '" & Me![Village name] & "'", CurConn, , , adCmdText
    16. End sub

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: openingdatabase using ADO

    If you are in Access you can use CurrentProject.connection to get the active connection.

    The error is because when you double click Access Mdb files it opens in Access as exclusive (for some reason). If you close the mdb and reopen through Access file>Open it should let you run the code and connect. But as I pointed out above there is already an open connection to the current database.

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

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