By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,985 Members | 1,694 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,985 IT Pros & Developers. It's quick & easy.

To join Ms-Access to VB try to write my code please help me

P: 38
Hi all

i could not joine MS Access table to VB the code i write below

Private Sub Form_Load()
Set cn = New ADODB.connection
cn.Provider = "Microsoft.jet.oledb.4.0"
cn.Open "C:\db1.mdb"
Set rs = New ADODB.Recordset
rs.Open "tbl", cn, adOpenDynamic, adLockOptimistic
Show
Call DisplayTheCurrentRecord
End Sub


My Database name is db1 and table name tbl.

Please help me.
Feb 4 '08 #1
Share this Question
Share on Google+
5 Replies


debasisdas
Expert 5K+
P: 8,127
what is the error message ?

try to use this sapmle for referrence for connection string

cn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program Files\Microsoft Visual Studio\VB98\biblio.mdb;Persist Security Info=False
"
Feb 4 '08 #2

P: 17
Hi all

i could not joine MS Access table to VB the code i write below

Private Sub Form_Load()
Set cn = New ADODB.connection
cn.Provider = "Microsoft.jet.oledb.4.0"
cn.Open "C:\db1.mdb"
Set rs = New ADODB.Recordset
rs.Open "tbl", cn, adOpenDynamic, adLockOptimistic
Show
Call DisplayTheCurrentRecord
End Sub


My Database name is db1 and table name tbl.

Please help me.

you have to change
rs.Open "select * from tbl", cn, adOpenDynamic, adLockOptimistic
Feb 4 '08 #3

dnb
P: 34
dnb
First add 'Microsoft ActiveX Data objects library 2.0' from references
First Save your project and database in the same folder.


Public cn As ADODB.Connection

Private Sub Form_Load()

Set cn = New ADODB.Connection
cn.Provider = "Microsoft.jet.oledb.4.0;"
cn.ConnectionString = App.Path & "/db1.mdb"
cn.CursorLocation = adUseClient
cn.Open

Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
If rs.State = 1 Then rs.Close
rs.Open "select * from tbl", cn, adOpenDynamic, adLockOptimistic

End Sub
Feb 4 '08 #4

P: 38
Alem
I Thank U all I have got my answer
I appreciate your help.

Thanks again.
Feb 4 '08 #5

debasisdas
Expert 5K+
P: 8,127
you have to change
rs.Open "select * from tbl", cn, adOpenDynamic, adLockOptimistic
not necessary

it can be any sql query, table ,view or materialized view name also.
Feb 4 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.