Results 1 to 4 of 4

Thread: [RESOLVED] connecting from outlook vba to access db through ado

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    586

    Resolved [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:
    1. Dim AccessConnect As String
    2.       Dim Conn1 As ADODB.Connection
    3.       Dim Rs1 As ADODB.Recordset
    4.       Dim StrDbg As String
    5.      
    6.        AccessConnect = "Driver={Microsoft Access Driver (*.mdb)};" & _
    7.                      "Dbq=my_database.mdb;" & _
    8.                      "DefaultDir=P:\;"
    9.  
    10.       Conn1.ConnectionString = AccessConnect
    11.       Conn1.Open
    12.      
    13.       Set Rs1 = Conn1.Execute("SELECT * FROM Stations")
    14.       Rs1.MoveFirst
    15.       StrDbg = ""
    16.        
    17.        While Not (Rs1.EOF)
    18.             StrDbgp = StrDbg & "," & Rs1("station_no")
    19.             Rs1.MoveNext
    20.        Wend
    21.  
    22.        Rs1.close
    23.        Conn1.Close
    24.        Conn1.ConnectionString = ""
    -----------------------------------------

    any ideas why?
    Last edited by RobDog888; Dec 27th, 2005 at 02:02 PM. Reason: Added [vbcode] tags

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    586

    Re: connecting from outlook vba to access db through ado

    anyone?

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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:
    1. Set Conn1 = New ADODB.Connection
    Same with the recordset object.
    VB Code:
    1. 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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    586

    Re: connecting from outlook vba to access db through ado

    Thanks! works great

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width