i need a code for adodb which can link my form in vb to a table in ms access which contains
name and id as the fields.help please!! thanx

Function GetRecord()

Dim ConnectionStr As String
Dim Uconnection As ADODB.Connection
Dim rs As ADODB.Recordset


ConnectionStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DatabasePath & "\databasefilename.mdb;Persist Security Info=False"
Set Uconnection = New Connection
Uconnection.ConnectionString = ConnectionStr
Uconnection.CommandTimeout = 120000
Uconnection.Open
Set rs = New Recordset
rs.CursorLocation = adUseClient
strQry="Select Name,Id from tablename"
rs.Open strQry, Uconnection, adOpenDynamic, adLockOptimistic
strQry = ""
Set GetRecord = rs

End Function

this if your using a DE...

dim rs as new adodb.recordset
set rs = new adodb.recordset

if rs.state = 1 then rs.close
rs.open "SELECT NAME, ID FROM TABLE", DataEnvironment1.Connection1, adOpenDynamic, adLockOptimistic

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.