Hello, new person here 
Author Message
 Hello, new person here

I am trying to write some VB5 code to connect to and manipulate an
Access 2000 database.

Can VB 5 read an Access 2000 database?
All I get is an error message saying Unrecognized Database Format.
Do I need VB 6 to make this work?

Thank you.

    Dim myRS As New ADODB.Recordset

'set up connection string
    Const ConnectStr = "PROVIDER=Microsoft.Jet.OLEDB.3.51;Data
Source=C:\test.mdb"

'create new record set
    Set myRS = New ADODB.Recordset

'set property to automatically create a connection
    myRS.ActiveConnection = ConnectStr

'open recordset with query for all customer records
    'myRS.Open "Select * from customers"
    myRS.Open "Select * from info"

'check if recordset is empty
    If myRS.BOF And myRS.EOF Then
        MsgBox "Recordset is empty!", 16, "Empty recordset"
    Else
'make sure you're on the first record
        myRS.MoveFirst
'loop through 5 records to display company name
        For i = 1 To 5
            'MsgBox myRS.Fields("CompanyName"), vbInformation,
"Company #" & i
            MsgBox myRS.Fields("Name"), vbInformation, "Company #" & i
'move to next record
            myRS.MoveNext
        Next i

'close recordset
        myRS.Close
    End If

'set to nothing to eliminate object
    Set myRS = Nothing
    End

---
Allen



Thu, 15 Sep 2005 09:26:51 GMT  
 Hello, new person here

Quote:
> I am trying to write some VB5 code to connect to and manipulate an
> Access 2000 database.

> Can VB 5 read an Access 2000 database?
> All I get is an error message saying Unrecognized Database Format.
> Do I need VB 6 to make this work?

> Thank you.

>     Dim myRS As New ADODB.Recordset

> 'set up connection string
>     Const ConnectStr = "PROVIDER=Microsoft.Jet.OLEDB.3.51;Data
> Source=C:\test.mdb"

> 'create new record set
>     Set myRS = New ADODB.Recordset

> 'set property to automatically create a connection
>     myRS.ActiveConnection = ConnectStr

> 'open recordset with query for all customer records
>     'myRS.Open "Select * from customers"
>     myRS.Open "Select * from info"

> 'check if recordset is empty
>     If myRS.BOF And myRS.EOF Then
>         MsgBox "Recordset is empty!", 16, "Empty recordset"
>     Else
> 'make sure you're on the first record
>         myRS.MoveFirst
> 'loop through 5 records to display company name
>         For i = 1 To 5
>             'MsgBox myRS.Fields("CompanyName"), vbInformation,
> "Company #" & i
>             MsgBox myRS.Fields("Name"), vbInformation, "Company #" & i
> 'move to next record
>             myRS.MoveNext
>         Next i

> 'close recordset
>         myRS.Close
>     End If

> 'set to nothing to eliminate object
>     Set myRS = Nothing
>     End

If you convert your database to Access97 it should work, or you could change
3.51 to 4.0 in your connection string.

For examples of connection strings:
http://www.able-consulting.com/ADO_Conn.htm

HTH



Thu, 15 Sep 2005 09:43:43 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. New person needs help!

2. From a new vb person wanting to know more

3. Cannot add a new Person/Task to Team Manager through OLE automation

4. Help - New VB person has a question about learning VB.

5. render Hello.xml + Hello.xsl into PrintDocument ?

6. Hello, i am new at programming..

7. Hello, i'm new

8. Hello to all, I'm new in this group

9. Very smart person needed here

10. Mapi Code to a faxServer instead of a Email person

11. To the person doing the Skills Search query

12. Help : sending reports to specific persons

 

 
Powered by phpBB® Forum Software