VBA SUB not found when calling from a marco (1 Viewer)

GregoryWest

Registered User.
Local time
Today, 09:17
Joined
Apr 13, 2014
Messages
161
I have a temp macro that has one step: Run Code : MakeExp


Inside my Module1 I have the following:


Public Sub MakeExp()

Dim rs_in As DAO.Recordset
Dim rs_out As DAO.Recordset
Dim strSql_in As String
Dim strSql_out As String
Dim ExpName As String 'Path and name of text file

---A ton more lines
sline = sline & slegal & Chr(34)
rs_in.MoveNext
Loop
Print #ExpNumber, sline
Close #ExpNumber
Close rs_in
End Sub

But when I run the macro I get the following error:
MicroSoft Access can not find the name 'MakeExp' you entered in the expression


Can anyone shed light on why this might not be working? Did I forget about telling Access the code is in Module1 (dont think I need to do that.....)
 

June7

AWF VIP
Local time
Today, 06:17
Joined
Mar 9, 2014
Messages
5,423
Make it a Function instead of Sub.

But why use macro?
 

GregoryWest

Registered User.
Local time
Today, 09:17
Joined
Apr 13, 2014
Messages
161
I do get the same error message, with a function. The reason for a macro is just to test. Been having a few little problems, and thought this should work for sure.... but it doesn't
 

June7

AWF VIP
Local time
Today, 06:17
Joined
Mar 9, 2014
Messages
5,423
Works for me. Need to know your macro code.
 

isladogs

MVP / VIP
Local time
Today, 14:17
Joined
Jan 14, 2017
Messages
18,186
As already stated, you can call functions in macros but not subs
Use Run Code in the macro command.
Intellisense will kick in to allow autocomplete to run.
Make sure you have () at the end of the function name

Testing is much easier using vba.
 

GregoryWest

Registered User.
Local time
Today, 09:17
Joined
Apr 13, 2014
Messages
161
The macro is : RunCode, with MakeExp in the function name field.


I have been wondering, if there could be some sort of corruption in the avvdb. If so what would be the best way to test/fix?
 

Gasman

Enthusiastic Amateur
Local time
Today, 14:17
Joined
Sep 21, 2011
Messages
14,042
As mentioned it should be MakeExp()

If you use the builder, that is what it will place in for the Argument
 

GregoryWest

Registered User.
Local time
Today, 09:17
Joined
Apr 13, 2014
Messages
161
WOW do I feel stupid. Been looking at that code for a few days now, did not even notice the lack of the (). Sigh, getting too old for this.



As mentioned it should be MakeExp()

If you use the builder, that is what it will place in for the Argument
 

isladogs

MVP / VIP
Local time
Today, 14:17
Joined
Jan 14, 2017
Messages
18,186
If you use the builder, that is what it will place in for the Argument

Actually if you use intellisense, it will only add the (
You need to add the ) yourself.
I assume the reason is that you may need to specify a function argument before adding the )
 

Gasman

Enthusiastic Amateur
Local time
Today, 14:17
Joined
Sep 21, 2011
Messages
14,042
Care to make it Solved, by Thread Tools in the post header.?
 

Users who are viewing this thread

Top Bottom