I cannot running a function with macro (1 Viewer)

masoud_sedighy

Registered User.
Local time
Today, 08:42
Joined
Dec 10, 2011
Messages
132
When I click the buttonA in my form, it runs a macro that there are some update query and a RunCode Action inside that.
update queries will be run buy RunCode does not execute function

Function Name of that is Update_Trend_Line_by_Month ()
I have made a module and put this function inside that:

Public Function Update_Trend_Line_by_Month()

Dim qdef As DAO.QueryDef
Set qdef = CurrentDb.CreateQueryDef("")
qdef.Connect = CurrentDb.TableDefs("[ASBUILT_LIST]").Connect
qdef.SQL = "EXEC Update_Asbuilt2"
qdef.ReturnsRecords = False ''avoid 3065 error
qdef.Execute

MsgBox "As Built list updated"

End Sub

when I click ButtonA Update queries will be execute but function Update_Trend_Line_by_Month () does not execute.

But when I put the code of this single function (VBA) to the button click event of another form it runs without problem.
But when it is inside macros with some other actions like update queries,
will be run but function does not execute.

Please help how I can solve my problem.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:42
Joined
Aug 30, 2003
Messages
36,124
The module doesn't have the same name as the function, does it?
 

masoud_sedighy

Registered User.
Local time
Today, 08:42
Joined
Dec 10, 2011
Messages
132
Name of module is ( module1)
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:42
Joined
Aug 30, 2003
Messages
36,124
Is the function argument of RunCode

Update_Trend_Line_by_Month()

If so, that should work. What does the whole macro look like? I don't use them, but it might help to see it all.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 08:42
Joined
Oct 29, 2018
Messages
21,456
Hi. Is your file stored in a Trusted Location or did you click the Enable Content button?
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:42
Joined
Aug 30, 2003
Messages
36,124
I don't think the other things would be running if not.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 08:42
Joined
Oct 29, 2018
Messages
21,456
I don't think the other things would be running if not.
Embedded macros (with safe actions) should run even for non-trusted files. I think...
 

Users who are viewing this thread

Top Bottom