Results 1 to 11 of 11

Thread: Acces

  1. #1

    Thread Starter
    Addicted Member Fredn's Avatar
    Join Date
    Sep 2001
    Location
    Belgium
    Posts
    135

    Acces

    Can i open a database connection to an Acces 2000 database using a connectionstring?
    (like i open a SQLserver database?)

    The following code doesn't work; can you make it work?
    VB Code:
    1. 'references: Microsoft ActiveX Data Objects 2.6 Library
    2.  
    3. Dim Conn As ADODB.Connection
    4. Dim RS As ADODB.Recordset
    5. Dim CS As String
    6.  
    7. CS = "DRIVER={Microsoft Access Driver (*.mdb)};" & "DBQ=C:\ProjectsVB\Experiment\testdb.mdb;DefaultDir=;UID=;PWD=;"
    8.  
    9. Conn.Open CS
    Who ' tha man ??

  2. #2
    Member
    Join Date
    Jan 2001
    Location
    Richmond, VA
    Posts
    59
    You declare the connection and the recordset but you never instantiate them. Try adding:

    Set Conn = New Connection

    Before opening connection.

    Note: you will also have add this:

    Set RS = New RecordSet

  3. #3

    Thread Starter
    Addicted Member Fredn's Avatar
    Join Date
    Sep 2001
    Location
    Belgium
    Posts
    135
    That's great help ! It works now, but now i have a problem with Conn.Open CS

    Is my connectionstring build right?
    Who ' tha man ??

  4. #4

    Thread Starter
    Addicted Member Fredn's Avatar
    Join Date
    Sep 2001
    Location
    Belgium
    Posts
    135
    I'm sorry, the problem is not that. My connection opens, but it is with something else i had problems:

    VB Code:
    1. Set Conn = New ADODB.Connection
    2. Set RS = New ADODB.Recordset
    3. CS = "DRIVER={Microsoft Access Driver (*.mdb)};" & "DBQ=C:\ProjectsVB\Experiment\testdb.mdb;DefaultDir=;UID=;PWD=;"
    4. Conn.Open CS
    5. SQL = "Select * from tb_Customers"
    6. Set RS = Conn.Execute(SQL)
    7. RS.MoveFirst
    8. RS.MoveLast
    9. MsgBox RS.RecordCount
    10. Set Conn = Nothing
    11. Set RS = Nothing

    The error occurs on RS.Movelast. This seems to be a problem with this recordset.
    When i don't do movelast and movefirst, i get RecordCount = -1, although there are several records in my table.
    Who ' tha man ??

  5. #5
    Member
    Join Date
    Jan 2001
    Location
    Richmond, VA
    Posts
    59
    By default you are opening the recordset with server side cursor.
    Try adding this:

    Conn.CursorLocation = adUseClient

  6. #6

    Thread Starter
    Addicted Member Fredn's Avatar
    Join Date
    Sep 2001
    Location
    Belgium
    Posts
    135
    This doesn't work. I also tried changing the .CursorType to each of the 4 types, but none of them works. I always get a message "Rowset does not support fetching backwards"
    Who ' tha man ??

  7. #7
    Member
    Join Date
    Jan 2001
    Location
    Richmond, VA
    Posts
    59
    Not sure what to tell you. This works for me:
    ----------------------------------------------------------
    Option Explicit
    Private adoRs As New ADODB.Recordset
    Private Conn As New ADODB.Connection

    Private Sub Form_Load()

    Conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=G:\Genetics\Genetics.mdb;Persist Security Info=False"
    Conn.CursorLocation = adUseClient
    Conn.Open

    Set adoRs = Conn.Execute("Select * from change")

    adoRs.MoveFirst
    adoRs.MoveLast

    MsgBox adoRs.RecordCount

    End Sub

    Server side cursors will always return -1 for a record count.

  8. #8

    Thread Starter
    Addicted Member Fredn's Avatar
    Join Date
    Sep 2001
    Location
    Belgium
    Posts
    135

    Nice Job !!

    This works for me too, thank you very much.

    Your connectionstring was the one i was looking for. The one i used came from some site i found, but i already guessed there was something odd.

    Now i can continue with my program...
    thanks again

    --> Why is it always the easy stuff i don't know ...
    Who ' tha man ??

  9. #9

    Thread Starter
    Addicted Member Fredn's Avatar
    Join Date
    Sep 2001
    Location
    Belgium
    Posts
    135

    Showing data in Grid

    I want to show the results of my query in a grid.

    Can i say something like:
    Grid.recordsource = RS ???

    What grid do i have to take then? (i see 3 kinds of them: datagrid control, data bound grid control, ms flex grid control)
    Who ' tha man ??

  10. #10
    Member
    Join Date
    Jan 2001
    Location
    Richmond, VA
    Posts
    59
    Set datagrid1.datasource = rs

    The datagrid control works fine.

  11. #11

    Thread Starter
    Addicted Member Fredn's Avatar
    Join Date
    Sep 2001
    Location
    Belgium
    Posts
    135
    What is the difference between datagrid and data bound grid? And flex grid, what is that used for?

    I first tried this thing:
    DGrid.DataSource = RS
    But it didn't work.

    In your example i saw that i had to do:
    SET dgrid.datasource = RS
    (this works)

    When do i have to use Set and when not?
    Who ' tha man ??

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