Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

connect to access

Status
Not open for further replies.

makisbest

Technical User
Mar 3, 2005
125
GR
hi

How I can connect to a table in my access database
with code

thank you
 
do you mean like read data from table or something else?
 
In your project, add a reference to Microsoft ActiveX Data Objects

Search this site and the web for help on using ADO
 
Here is one example of a FAQ on this site: faq222-3735
 
At this code I get this error why?

code
Sub Get_Accountno()
Dim Conn as ADODB.Connection 'Connection
Dim Rs as ADODB.Recordset 'Recordset
Dim strQuery As String 'Command

Set Conn = New ADODB.Connection
With Conn
.CursorLocation = adUseClient
.ConnectionString= "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\MyPath\myDatabase.mdb"
.Open
End With

strQuery = "SELECT Accountno FROM tblTable " & _
"WHERE Username = 'BillK'"

Set Rs = New ADODB.Recordset
With Rs
Set .ActiveConnection = Conn
.CursorType = adOpenStatic
.Source = strQuery
.Open <----------------
End With

Is something wrong with this line.
 
maki

Would you share the error number & description ?

Gerassimos - kai ego makis e?!?

 
Try:
Code:
strQuery = "SELECT Accountno FROM tblTable " & _
"WHERE  Username = 'BillK'"

Set Rs = New ADODB.Recordset
    With Rs
        Set .ActiveConnection = Conn
        .CursorType = adOpenStatic
        [b].Open strQuery, Conn[/b]
    End With
HTH

---- Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top