Link to home
Start Free TrialLog in
Avatar of lcha
lchaFlag for United States of America

asked on

VB program connecting to Access DB - arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.

Hello experts,

I am learning how to write a program in Visual Studio 2008, using visual basic .net and ADO (referencing Microsoft Active X Data Objects 2.8 Library).

Using the code below, it fails at the line where I set a recordset's .source value to a sql string (see code below)

The error I'm getting is " arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.

Pls advise if you can see the issue here.   Thanks in advance!
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim strSQL As String

cn.Open("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Documents and Settings\Administrator\My Documents\testdb.accdb")

strSQL = "SELECT * FROM table1;"

                  With rs
                        .ActiveConnection = cn
                        .Source = strSQL
                        .Open()
                    End With
                    rs.Open()

                    If rs.EOF = False Then
                        rs.MoveFirst()
                    End If
                    Do
                        MsgBox(rs.Fields("Field1"))
                        rs.MoveNext()

                    Loop Until rs.EOF = True

                    cn.Close()
                    cn = Nothing
                    rs = Nothing

Open in new window

Avatar of jppinto
jppinto
Flag of Portugal image

Shouldn't you put .mdb on this line of code? Where you have this:

cn.Open("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Documents and Settings\Administrator\My Documents\testdb.accdb")

You should have this:

cn.Open("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Documents and Settings\Administrator\My Documents\testdb.mdb")

jppinto
Avatar of kaufmed
Is there a reason why you are calling Open() twice on the RecordSet? Once within the "With" and once just after it.
Avatar of lcha

ASKER

You can please disregard the calling of open twice ... it's not like that in the current code.  

Also, I am using Access 2007, so the database extension is correct ... .accdb

thanks
Avatar of lcha

ASKER

raising points on this
ASKER CERTIFIED SOLUTION
Avatar of jppinto
jppinto
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lcha

ASKER

great, appreciate this.   I'll continue working on this tommorrow and keep you posted.   thanks.
Avatar of lcha

ASKER

thank you!   I got it working now!