Go Back   Access World Forums > Microsoft Access Discussion > Macros

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 01-10-2019, 02:02 PM   #1
bbxrider
Newly Registered User
 
Join Date: May 2009
Posts: 30
Thanks: 1
Thanked 0 Times in 0 Posts
bbxrider is on a distinguished road
start up autoexec macro not invoking function

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?
Attached Images
File Type: png autoexec.2.png (6.5 KB, 53 views)
File Type: png autoexec.1.png (14.5 KB, 47 views)

bbxrider is offline   Reply With Quote
Old 01-10-2019, 02:04 PM   #2
theDBguy
I知 here to help
 
theDBguy's Avatar
 
Join Date: Oct 2018
Location: SunnySandyEggo
Posts: 2,742
Thanks: 33
Thanked 654 Times in 637 Posts
theDBguy will become famous soon enough theDBguy will become famous soon enough
Re: start up autoexec macro not invoking function

Yes, you can run a function, but it has to be declared Public and stored in a Standard Module.
__________________
Just my 2 cents...

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
theDBguy is offline   Reply With Quote
Old 01-10-2019, 02:41 PM   #3
bbxrider
Newly Registered User
 
Join Date: May 2009
Posts: 30
Thanks: 1
Thanked 0 Times in 0 Posts
bbxrider is on a distinguished road
Re: start up autoexec macro not invoking function

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

bbxrider is offline   Reply With Quote
Old 01-10-2019, 04:04 PM   #4
theDBguy
I知 here to help
 
theDBguy's Avatar
 
Join Date: Oct 2018
Location: SunnySandyEggo
Posts: 2,742
Thanks: 33
Thanked 654 Times in 637 Posts
theDBguy will become famous soon enough theDBguy will become famous soon enough
Re: start up autoexec macro not invoking function

Hi. What is the name of the Standard Module? Make sure it’s not the same as the name of the function.
__________________
Just my 2 cents...

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
theDBguy is offline   Reply With Quote
Old 01-10-2019, 05:21 PM   #5
bbxrider
Newly Registered User
 
Join Date: May 2009
Posts: 30
Thanks: 1
Thanked 0 Times in 0 Posts
bbxrider is on a distinguished road
Re: start up autoexec macro not invoking function

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
Attached Images
File Type: png standard.module1.PNG (18.4 KB, 38 views)

Last edited by bbxrider; 01-10-2019 at 05:39 PM.
bbxrider is offline   Reply With Quote
Old 01-10-2019, 07:21 PM   #6
theDBguy
I知 here to help
 
theDBguy's Avatar
 
Join Date: Oct 2018
Location: SunnySandyEggo
Posts: 2,742
Thanks: 33
Thanked 654 Times in 637 Posts
theDBguy will become famous soon enough theDBguy will become famous soon enough
Re: start up autoexec macro not invoking function

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.
__________________
Just my 2 cents...

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
theDBguy is offline   Reply With Quote
Old 01-10-2019, 07:34 PM   #7
Micron
Newly Registered User
 
Join Date: Oct 2018
Location: Ontario, Canada
Posts: 616
Thanks: 3
Thanked 124 Times in 119 Posts
Micron will become famous soon enough Micron will become famous soon enough
Re: start up autoexec macro not invoking function

cross posted
http://www.accessforums.net/showthread.php?t=75177

Micron is offline   Reply With Quote
Old 01-10-2019, 07:49 PM   #8
MajP
Newly Registered User
 
Join Date: May 2018
Location: USA baby
Posts: 1,567
Thanks: 25
Thanked 471 Times in 447 Posts
MajP will become famous soon enough MajP will become famous soon enough
Re: start up autoexec macro not invoking function

Quote:
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.
Attached Images
File Type: jpg module-properties-2.jpg (25.7 KB, 108 views)
MajP is offline   Reply With Quote
Old 01-10-2019, 11:18 PM   #9
bbxrider
Newly Registered User
 
Join Date: May 2009
Posts: 30
Thanks: 1
Thanked 0 Times in 0 Posts
bbxrider is on a distinguished road
Re: start up autoexec macro not invoking function

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
bbxrider is offline   Reply With Quote
Old 01-11-2019, 08:27 AM   #10
theDBguy
I知 here to help
 
theDBguy's Avatar
 
Join Date: Oct 2018
Location: SunnySandyEggo
Posts: 2,742
Thanks: 33
Thanked 654 Times in 637 Posts
theDBguy will become famous soon enough theDBguy will become famous soon enough
Re: start up autoexec macro not invoking function

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.
__________________
Just my 2 cents...

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
theDBguy is offline   Reply With Quote
Old 01-11-2019, 10:38 AM   #11
bbxrider
Newly Registered User
 
Join Date: May 2009
Posts: 30
Thanks: 1
Thanked 0 Times in 0 Posts
bbxrider is on a distinguished road
Re: start up autoexec macro not invoking function

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
bbxrider is offline   Reply With Quote
Old 01-11-2019, 10:41 AM   #12
theDBguy
I知 here to help
 
theDBguy's Avatar
 
Join Date: Oct 2018
Location: SunnySandyEggo
Posts: 2,742
Thanks: 33
Thanked 654 Times in 637 Posts
theDBguy will become famous soon enough theDBguy will become famous soon enough
Re: start up autoexec macro not invoking function

Hi. Glad to hear you got it sorted out. Good luck with your project.
__________________
Just my 2 cents...

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
theDBguy is offline   Reply With Quote
Old 01-11-2019, 10:45 AM   #13
bbxrider
Newly Registered User
 
Join Date: May 2009
Posts: 30
Thanks: 1
Thanked 0 Times in 0 Posts
bbxrider is on a distinguished road
Re: start up autoexec macro not invoking function

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

bbxrider is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
autoexec macro geno General 1 03-30-2012 08:04 AM
Make Table on Start up - Autoexec? Yoplumpy Modules & VBA 11 07-06-2010 06:45 AM
AutoExec to start .swf NigelShaw General 1 08-16-2008 04:14 PM
AutoExec Macro Name miguel vasquez Macros 1 04-30-2007 07:31 AM
Invoking function on form with Toolbar button KeithWilliams Forms 3 03-09-2004 01:04 AM




All times are GMT -8. The time now is 07:48 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World