Link to home
Start Free TrialLog in
Avatar of hnguyenhn
hnguyenhn

asked on

Error when runing a sub procedure in macro

Hi,
I have created a sub procedure in module window, now I want to run it as a macro. In order to call it I chose Action = RunCode and key in the SyncDB() (It's the sub procedure name). Then I tried to run but it said "THe expression you entered has a function name that Microsoft cac't find"
Please help me

THank
ASKER CERTIFIED SOLUTION
Avatar of nico5038
nico5038
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Paurths
Paurths

would be easier if u showed the procedure(s) (code) here.
Nico is right, you cannot run SUB procedure's in a macro, you can only run FUNCTIONS

As a workaround you can

1. Change your sub into a function
2. Create a function that calls the sub
ex.
FUNCTION KOKO
  Call SyncDB
END FUNCTION
in the macro put,  KOKO in the RunCode action prop

perove
Avatar of hnguyenhn

ASKER

Hi,
Here is my code and actually I've changed it to function also but it isn't working

Option Compare Database
Option Explicit


Function SynchronizeDB()
Dim dbDesign As Database

Set dbDesign = OpenDatabase("D:\Hieu\Design database\Leads.mdb")
dbDesign.Synchronize "D:\Hieu\Leads_of_Malc.mdb", dbRepImpExpChanges
dbDesign.Close

End Function

THe name of module is the same as function name(SynchronizeDB)
I just want to make a macro that every time users start application then it will automatically sync

Thank
Hieu


Hi,
Let me explain more. Basically I have a Design Master DB(for replication), I created a synchronization function in a module and make it replicable, I can run this function from Design master DB(of cource there's an error) but I cannot run it at master replicable DB, even I re-sync before run it. My idea is to make an automated synchronization function and whenever users want to sync they just run that function

How do I make it work?
Did you try with prefixing the module and function to get unique names like: modSynchronizeDB and fncSynchronizeDB.

Nic;o)
hnguyenhn:

Here's hoping you'll take care of this question too.

thanks!
amp
community support moderator
hnguyenhn:

Your open questions:

https://www.experts-exchange.com/jsp/qShow.jsp?qid=20142680
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20143250
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20131155
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11768578
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11676698

To assist you in your cleanup, I'm providing the following guidelines:

1.  Stay active in your questions and provide feedback whenever possible. Likewise, when feedback has not been provided by the experts, commenting again makes them receive an email notification, and they may provide you with further information. Experts have no other method of searching for questions in which they have commented, except manually.

2.  Award points by hitting the Accept Comment As Answer button located above and to the left of that expert's comment.

3.  When grading, be sure to read:
https://www.experts-exchange.com/jsp/cmtyQuestAnswer.jsp#3
to ensure that you understand the grading system here at EE. If you grade less than an A, you must explain why.

4.  Questions that were not helpful to you should be PAQ'd (stored in the database for their valuable content?even if not valuable to you) or deleted. To PAQ or delete a question, you must first post your intent in that question to make the experts aware. Then, if no experts object after three full days, you can post a zero-point question at community support to request deletion or PAQ. Please include the link(s) to the question(s).
CS:  https://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
At that point, a moderator can refund your points and PAQ or delete the question for you. The delete button does not work.

5.  If you fail to respond to this cleanup request, I must report you to the Community Support Administrator for further action.

Our intent is to get the questions cleaned up, and not to embarrass or shame anyone. If you have any questions or need further assistance at all, feel free to ask me in this question or post a zero-point question at CS. We are very happy to help you in this task!


thanks!
amp
community support moderator

1/24
Per recommendation, force-accepted by
Netminder
CS Moderator