[RESOLVED] connecting from outlook vba to access db through ado
hey,
I'm trying to connect outlook to access through ado.
I get runtime error 91: " object variable or with block variable not set" .
here's my code (vba in outlook):
---------------------------------------
VB Code:
Dim AccessConnect As String
Dim Conn1 As ADODB.Connection
Dim Rs1 As ADODB.Recordset
Dim StrDbg As String
AccessConnect = "Driver={Microsoft Access Driver (*.mdb)};" & _
"Dbq=my_database.mdb;" & _
"DefaultDir=P:\;"
Conn1.ConnectionString = AccessConnect
Conn1.Open
Set Rs1 = Conn1.Execute("SELECT * FROM Stations")
Rs1.MoveFirst
StrDbg = ""
While Not (Rs1.EOF)
StrDbgp = StrDbg & "," & Rs1("station_no")
Rs1.MoveNext
Wend
Rs1.close
Conn1.Close
Conn1.ConnectionString = ""
-----------------------------------------
any ideas why?
Re: connecting from outlook vba to access db through ado
Re: connecting from outlook vba to access db through ado
Thats because you need to create a new instance of the connection object first before it can be used.
VB Code:
Set Conn1 = New ADODB.Connection
Same with the recordset object.
VB Code:
Set Rs1 = New ADODB.Recordset
Re: connecting from outlook vba to access db through ado