access database (adodb)from excel vba

A

AskExcel

hi all,
may i know the follow to connect to database able to define in VBA (excel)?
i tried to use but when run i got the message compile error: user defined
type not defined at Dim rstest as adodb.recordset
if this cannot be done in VBA, what is the alternative to access database
from excel?
please advise.
thank you very much


Public cnsql As ADODB.Connection
Sub Main()
Set cnsql = New ADODB.Connection
With cnsql
..Provider = "xx;" & _
"Data Source=xx;" & _
"Initial Catalog=xx;" & _
"User Id=xx;" & _
"Password=xx"
..Open
End With
End Sub

private sub
Dim rstest As ADODB.Recordset
Set rstest = New ADODB.Recordset
With rstest
..ActiveConnection = xx
..CursorType = adOpenKeyset
..LockType = adLockOptimistic
..Open "sql statement"'"
End With
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top