|
-
Dec 27th, 2005, 07:38 AM
#1
Thread Starter
Fanatic Member
[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?
Last edited by RobDog888; Dec 27th, 2005 at 02:02 PM.
Reason: Added [vbcode] tags
-
Dec 27th, 2005, 01:36 PM
#2
Thread Starter
Fanatic Member
Re: connecting from outlook vba to access db through ado
-
Dec 27th, 2005, 02:04 PM
#3
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
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Dec 29th, 2005, 05:12 PM
#4
Thread Starter
Fanatic Member
Re: connecting from outlook vba to access db through ado
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|