start up autoexec macro not invoking function (1 Viewer)

bbxrider

Registered User.
Local time
Today, 05:04
Joined
May 19, 2009
Messages
30
not sure if to post this in macro or modules but trying here first

created a 'autoexec' macro, it does run at startup or I can manually run
I thought it could invoke a vba function, that is what I need, to exec some code, but the macro can't seem to find the function
see pics of autoexec, and error message
and yes I have double/triple checked that the function is there
I have 2 modules in the db and I just put the function code for the autoexec in one of the modules
so....
I can run a vba function, yes?
does it matter where to put the function?
 

Attachments

  • autoexec.2.png
    autoexec.2.png
    6.5 KB · Views: 160
  • autoexec.1.png
    autoexec.1.png
    14.5 KB · Views: 156

theDBguy

I’m here to help
Staff member
Local time
Today, 05:04
Joined
Oct 29, 2018
Messages
21,357
Yes, you can run a function, but it has to be declared Public and stored in a Standard Module.
 

bbxrider

Registered User.
Local time
Today, 05:04
Joined
May 19, 2009
Messages
30
thanks for the reply, I just made the function explicitly declared public but still same result. the db has 2 standard modules, the one I chose has some public variables I need to access in the function.

Code:
Public Function delete_import_table() As String
   Set db = CurrentDb()
   'this is the table with universe all columns to populate from source tables
   For Each tdf In db.TableDefs
    ' iterate through all  tables
      If (tdf.Name Like "someTableName*") Then
         DoCmd.SetWarnings False
         DoCmd.Close acTable, tdf.name, acSaveYes
         DoCmd.DeleteObject acTable = acDefault, tdf.Name
        End If
            
   Next tdf 'next source table

End Function
 

theDBguy

I’m here to help
Staff member
Local time
Today, 05:04
Joined
Oct 29, 2018
Messages
21,357
Hi. What is the name of the Standard Module? Make sure it’s not the same as the name of the function.
 

bbxrider

Registered User.
Local time
Today, 05:04
Joined
May 19, 2009
Messages
30
thanks for the ongoing replies
in this case its "module2", but don't understand your reply,
in my access 2016, there is no option to name modules, you just insert new, it asks standard or class module, it assigns names, module1, module2, etc and you don't have any option to rename it that I know of, see attached right click of my module2, there is no rename option. so unless you name a function literally say "module2" that would be the only way to have module and function the same names
 

Attachments

  • standard.module1.PNG
    standard.module1.PNG
    18.4 KB · Views: 139
Last edited:

theDBguy

I’m here to help
Staff member
Local time
Today, 05:04
Joined
Oct 29, 2018
Messages
21,357
Hi. You can rename your modules by changing the Name property in the Properties box. Just for troubleshooting purposes, create a new public function with a simple MsgBox in it and then try to call in from your macro to see if you're able to do it.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 08:04
Joined
May 21, 2018
Messages
8,463
there is no option to name modules, you just insert new
In the vb designer you can configure what windows show. You may not be showing the properties window. Should look like this.


You can change the name in the project explorer (upper window) by right clicking on the name. Or in the below properties window by typing in the name field.
 

Attachments

  • module-properties-2.jpg
    module-properties-2.jpg
    25.7 KB · Views: 373

bbxrider

Registered User.
Local time
Today, 05:04
Joined
May 19, 2009
Messages
30
ok thanks, still not seeing the module name change ability, but...
that is not the issue for me right now, I have module2 which contains a public function that is specified in the autoexec macro, called
Code:
Public Function delete_import_table() As String
which is not the same name as module2, and it won't run with
access telling me it can't find it, please see orig post with error msg...
it was suggested it might not run because it was the same name as the standard module name, which is not the case so I'm still trying to figure out why
access can't find and/or can't run my function
 

theDBguy

I’m here to help
Staff member
Local time
Today, 05:04
Joined
Oct 29, 2018
Messages
21,357
Hi. Did you try my troubleshooting suggestion? Just wondering... It would at least give us an area to focus on, whether you can't run any function from a macro or there's something wrong with the function you're trying to run.
 

bbxrider

Registered User.
Local time
Today, 05:04
Joined
May 19, 2009
Messages
30
I just got an answer from a sister post in accessforums.net where I originally posted but that thread had seemed to have gone cold
the answer is you need to include "()" in the function name supplied to the macro, so in this case the function name in the autoexec macro is "delete_import_table()" instead of "delete_import_table"
it was also suggested to use a variant for function type but my setup is working with the function defined as string
thanks everybody
 

theDBguy

I’m here to help
Staff member
Local time
Today, 05:04
Joined
Oct 29, 2018
Messages
21,357
Hi. Glad to hear you got it sorted out. Good luck with your project.
 

bbxrider

Registered User.
Local time
Today, 05:04
Joined
May 19, 2009
Messages
30
and also thanks for showing how to change module name, so used to right click for properties just didn't notice the properties panel for name change below the main db panel, hoping to be more aware in the future
 

Users who are viewing this thread

Top Bottom