Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run a module from a acro 1

Status
Not open for further replies.

Cpreston

MIS
Mar 4, 2015
972
GB
Hi

I have a macro that runs several queries and all works ok.
I also have a module called ExportContacts that I need to be part of the same macro but I cannot find a way to add it.
I have tried to add it as a RunCode but then it does not recognise the name of the module (I checked the name and it is ok)

Bit lost how I can add it in. Any ideas please.

Thanks
 
The name of the (standard?) module is not important.
What is important is how you declared the Sub(s) or Function(s) in this module. Are they all Private or Public?

If you have something like in the module:
Code:
Public Function Do_This(...
You can simply do anywhere in your application:
Code:
SomeVar = Do_This

But if they are declared as Private, they are not available from outside of the Module.

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
A possible reason for this you have used "ExportContacts" as the name instead of "ExportContacts()" - must have the brackets.

Thanks
Michael
 
Hi

This is the code so not sure what is is and why it is not picking it up, how do I fix please. Thanks

Sub ExportContacts()
DoCmd.TransferText acExportDelim, "ContactsNew Export", _
"Contacts", "I:\Trex\Database 2013\ContactsNew.csv", True
End Sub
 
When you adding it to your macro in the "RunCode", put the Function name as "ExportContacts()".

Thanks
Michael
 
HI

I have added into the macro aRinCode with the function name of ExportContacts()

When I run the macro it comes to the runcode part and gives the below

The expression you entered had a function name Microsoft Access cannot find

Any ideas please, thanks
 
Change it to:

Code:
Function ExportContacts()
DoCmd.TransferText acExportDelim, "ContactsNew Export", _
"Contacts", "I:\Trex\Database 2013\ContactsNew.csv", True
End Function

And also you can't call a Function procedure from a macro if the function name is the same as the module name.

Thanks
Michael

 
Hi

Sorry guys still not working same message as before

I have a runcode with the function name of ExportContacts()

The module as this code in it

Function ExportContacts()
DoCmd.TransferText acExportDelim, "ContactsNew Export", _
"Contacts", "I:\Trex\Database 2013\ContactsNew.csv", True
End Function

But I still get The expression you entered had a function name Microsoft Access cannot find
 
And your module name is not named "ExportContacts"?

Thanks
Michael
 
Under the Modules menu (where we have Tables/Queries/Forms etc...) is the module named
ExportContacts

 
Yes, do you have a module with the name "ExportContacts"? If you do, that needs to be renamed or you have to rename the Function - you can't have the function\sub and the module name the same.

Thanks
Michael
 
Ok seems to have solved the issue, I renamed the module. I will give it a blast in the morning when we have new data to test with

Thanks for your help and patience.
 
Great, glad you got it working, you're welcome.

Thanks
Michael
 
Hi

Sorry coma across another problem with it now.
have had to transfer all the tables etc... into another database so I can run it as part of another database

It keeps crashing on the module Conatctsout (the difference also is the table is now called ContactsNew, due a table already being named this in the database)

Function ExportContacts()
DoCmd.TransferText acExportDelim, "ContactsNew Export", _
"ContactsNew", "I:\Trex\Database 2013\ContactsNew.csv", True
End Function

I have a hunch it may be the "ContactsNew Export" part, which I believe I named manually when running the export from the table in the old database but I cannot recreate this procedure.

Any ideas please
 
Its ok I sussed it and managed to Save As , all working again

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top