Results 1 to 5 of 5

Thread: Access function returning a collection

  1. #1

    Thread Starter
    Frenzied Member vbgladiator's Avatar
    Join Date
    May 2001
    Posts
    1,950

    Access function returning a collection

    Hey,

    I have a VBA program in Access and I just created a new function.
    I want it to return a collection of objects that I create inside the function.

    Code:
    Private Function GetADPOrderDetails(OrderID As Long, AgencyID As Long) As Collection
        Dim blah As New Collection
        Dim rs As Recordset
        Dim sSQL As String
        
             
        'some code
        
        rs.Close
        Set rs = Nothing
        GetADPOrderDetails = blah
    End Function
    I am getting an argument not optional error and the GetADPOrderDetails = blah line is highlighted.

    Can I not return collections in Ms-Access?

    Thanks,
    Don't anthropomorphize computers -- they hate it

  2. #2

    Re: Access function returning a collection

    try without =

  3. #3

    Thread Starter
    Frenzied Member vbgladiator's Avatar
    Join Date
    May 2001
    Posts
    1,950

    Re: Access function returning a collection

    byref argument type mismatch error if I ommit the equal sign.
    Don't anthropomorphize computers -- they hate it

  4. #4
    Frenzied Member David.Poundall's Avatar
    Join Date
    Sep 2002
    Location
    Robin Hood Land
    Posts
    1,457

    Re: Access function returning a collection

    You need to

    Code:
    Set GetADPOrderDetails = blah
    David

    Learn the Rules so that you know how to break them properly.

    Printing dll dBTools MZTools Winsock API WinsockVB More Winsock SGrid2 MSChart Mail2Web

    If you have found this thread useful then read this

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

    Re: Access function returning a collection

    FYI, you could always just return the recordset. If you are going to be doing
    any mods to the records in it, it may be helpful to have the rs instead of the collection.

    Yes, Set is the the correct solution. David

    HTH
    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

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