View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
AskExcel AskExcel is offline
external usenet poster
 
Posts: 19
Default access database (adodb)from excel vba

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