Results 1 to 7 of 7
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    2,095

    AutoExec can't find Public function


    I must be going blind or something. A standard module containing a Public function and Access can't find it when I run the AutoExec.

    Click image for larger version. 

Name:	002.jpg 
Views:	21 
Size:	21.6 KB 
ID:	53076
    Click image for larger version. 

Name:	001.jpg 
Views:	21 
Size:	115.3 KB 
ID:	53077

  2. #2
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2021
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,740
    Never mind. I see that your call in autoexec appears correct.

  3. #3
    madpiet is offline Expert
    Windows 10 Office 365
    Join Date
    Feb 2023
    Posts
    564
    Maybe you did what I did... Here's my code:
    (Yep, it's really simple code on purpose)

    Code:
    Public Function GetTodaysDate() As Date    GetTodaysDate = Date
    End Function
    
    
    Public Function HelloToday()
        MsgBox "Today's date is " & Format(GetTodaysDate(), "MMM-DD-YYYY"), vbOKOnly
    End Function
    I tried calling it like 5 times like this in the macro:
    Function Name: HelloToday

    which is wrong. =) it should be

    Function Name: HelloToday() <--- note the parentheses.

    (it makes sense, though. "HelloToday" without the () would be interpreted as being a Sub and not a Function. Putting () at the end basically indicates "this is a function that I'm calling".

    I was getting some weird not helpful error, but once you put the parentheses in at the end, it works a champ. Lesson learned!

    Thanks, Bill.

  4. #4
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    2,095
    Not quite sure how your example changes things relative to my OP, as you can see from the screenshots, I include the parentheses both in the Function and the AutoExec.

  5. #5
    madpiet is offline Expert
    Windows 10 Office 365
    Join Date
    Feb 2023
    Posts
    564
    Okay, super weird. Your code looks right... no idea why it's not working.

    At this point, I'd import at least that function into a new database and see if you can get the macro to work. That's really odd. it's a bit of a reach, but what happens if you try to compile your VBA code?

  6. #6
    jojowhite's Avatar
    jojowhite is online now Competent Performer
    Windows 11 Access 2021
    Join Date
    Jan 2025
    Posts
    432
    while on VBA, Debug and compile your code, maybe there are some errors?

  7. #7
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    2,095
    Super weird is right! I created a new DB, copied the macro and general module from the failing DB to the new DB and ran the new DB without any problems. So, what's seen the screenshots in the OP works just fine.

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

Similar Threads

  1. Access AutoExec Macro Cannot Find Function
    By JuanTooTree in forum Access
    Replies: 10
    Last Post: 06-08-2023, 10:10 AM
  2. Autoexec failing to find designated function
    By GraeagleBill in forum Programming
    Replies: 7
    Last Post: 06-25-2022, 05:37 PM
  3. Replies: 3
    Last Post: 02-11-2020, 02:44 PM
  4. Replies: 1
    Last Post: 10-16-2019, 03:45 PM
  5. VBA Can't find Public Function
    By GraeagleBill in forum Programming
    Replies: 15
    Last Post: 03-17-2016, 09:38 PM

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