Results 1 to 11 of 11
  1. #1
    JuanTooTree is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    2

    Access AutoExec Macro Cannot Find Function

    Hi, I have had a look round here, and the net in general, and this question has been asked a lot, but the answers don't solve my problem.

    I've set up an AutoExec macro in Access 2010 to call a function (RunCode) called fRunMatchQuery, but it can't find it. I get the message "Microsoft Access cannot find the name 'fRunMatchQuery' you entered in the expression.

    Here is the function:
    Code:
    Public Function fRunMatchQuery()
        Dim datToday As Date
        Dim strDate As String
        
        datToday = Date
        strDate = Format(datToday, "ddmmyy")
        
        DoCmd.SetWarnings False
        
        DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qryMatch", _
            "V:\Data\ProductCode+FeatureCodes " & strDate & ".xlsx", True
        
        Call sMatch
        
        DoCmd.SetWarnings True
    End Function
    The function fRunMatchQuery is in a module called Module1, so it's not the same name issue which seems to be the most common cause of problems. And Module1 is a standard module created by right-clicking and inserting a new module, so it's not that the module is part of a form etc.

    The function works fine when I step through the VBA.

    I have the following VBA References set up (I'm not sure if they make any difference to this anyway):
    Visual Basic for Applications
    Microsoft Access 14.0 Object Library
    OLE Automation
    Microsoft Office 14.0 Access database engine Object Library


    Microsoft Excel 14.0 Object Library

    Does anyone have any idea what I'm doing wrong?

    Thanks in advance for any help you can provide.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    You've covered the usual suspects. Did you include the parentheses in the macro?


    fRunMatchQuery()

    If so, can you post the db here?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    JuanTooTree is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    2
    D'oh! I missed off the parenthesis.

    Thanks for your help Paul.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Happy to help! Welcome to the site by the way!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Raddle is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2021
    Posts
    60
    Hi
    I have a related question .. I just want to call a sub routine, just like I would a query or a report, from the left hand menu / navigation pane. I don't know how to achieve this. This is what I've done:

    Create a macro
    Add step to RunCode
    It asks for a Function not a routine?
    State the Sub name
    Run it

    And obvs is says it cannot find the Function name.

    I know this is basic but any help would be appreciated.

    ************* ok my bad - so there is a button to 'convert to Function' and then you can call that from another macro. Wow. Simple.

    What is the reason one cannot call the sub directly I wonder?

    Sorry to bother.

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716

  7. #7
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    Raddle,
    You have attached your post to a 10 year old thread????

    This works for me.
    Click image for larger version. 

Name:	AutoexecCallingFunction2023-06-05 10_25_05-Greenshot.jpg 
Views:	19 
Size:	119.9 KB 
ID:	50321

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Other thoughts, it has to be a public function in a standard module, and the function can not have the same name as a module.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,858
    It is the same with the switchboard.

    I just did this

    Code:
    Function OpenCommonForm(pOpenArgs As String)
    ' Open a form for Reports & Queries
    DoCmd.OpenForm "frmOpenObject", , , , , , pOpenArgs
    End Function
    Switchboard runs a macro, which RunsCode OpenCommonForm and passes a parameter.
    This form handled Forms, Queries and Reports depending on the parameter passed.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  10. #10
    Raddle is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2021
    Posts
    60
    Yes you could say i am a bit behind the times ... 10yr old thread, although I thought we were stronly encouraged to search and use existing content to help ourselves where we could, which is what I was (trying) to do.

    Thank you for coming back to me.

    If this happens again should I create a new thread?

    thank you so much everybody for coming back on this. Really appreciate the inputs

  11. #11
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 01-08-2013, 11:51 AM
  2. Replies: 7
    Last Post: 06-14-2012, 01:54 PM
  3. Help Stopping AutoExec Macro
    By drewetzel in forum Access
    Replies: 2
    Last Post: 10-03-2011, 10:51 AM
  4. Replies: 2
    Last Post: 06-20-2011, 09:20 AM
  5. Using parameter in autoexec macro
    By lchurch in forum Queries
    Replies: 0
    Last Post: 03-04-2009, 06:22 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums