How to call function name and pass into other function (1 Viewer)

tucker61

Registered User.
Local time
Today, 05:18
Joined
Jan 13, 2008
Messages
321
I am playing with some new code below to log the time that it takes to run a query.

So i have added a new function called Startlog and EndLog.
I want these to use the function name as i log this in my table, is there a easy way to pass the Function name to StartLog and EndLog so i dont have to type in all the time ?


Code:
Function OpenAuditsNoUser()
WarningsOff
    StartLog ("OpenAuditsNoUser")
    DoCmd.OpenQuery "Qry_Update Date for Closed jobs"
    ExportQuery "Open Audits", "SELECT * FROM Qry_Open_Audits;", , , Environ("Temp") & "\"
    EndLog ("OpenAuditsNoUser")
    Waitoff
End Function

Code:
Function StartLog(myReport)
WarningsOff
sUser = GetLongName
strsql = ("INSERT INTO tblqcreports ([User], [StartTime],[Report]) VALUES ( '" & GetLongName& "', '" & stime & "', '" & myReport & "');")
DoCmd.RunSQL strsql
WarningsOn
End Function

Function EndLog(myReport)
WarningsOff
strsql = "UPDATE tblqcreports SET tblqcreports.EndTime = Now()" & "WHERE tblqcreports.Report='" & myReport & "' AND tblqcreports.Endtime Is Null;"
DoCmd.RunSQL strsql
WarningsOn
End Function
 

theDBguy

I’m here to help
Staff member
Local time
Today, 05:18
Joined
Oct 29, 2018
Messages
21,467
Hi. Not sure... You could save some typing by simply assigning the name of the function to a variable. For example:
Code:
strFunctionName = "OpenAuditsNoUser"
StartLog strFunctionName
EndLog strFunctionName
Hope that helps...
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 08:18
Joined
Feb 19, 2002
Messages
43,257
Wouldn't it make more sense to use a single log record? You're doing everything in the same procedure.
Dim StartDT as DateTime
Dim EndDT as DateTime

StartDT = Now()
run query
EndDT = Now()
Write log record
 

tucker61

Registered User.
Local time
Today, 05:18
Joined
Jan 13, 2008
Messages
321
Wouldn't it make more sense to use a single log record? You're doing everything in the same procedure.
Dim StartDT as DateTime
Dim EndDT as DateTime

StartDT = Now()
run query
EndDT = Now()
Write log record
after thinking about it, i dont think that would work as i am going to run this on about 20 reports,
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 08:18
Joined
Feb 19, 2002
Messages
43,257
Why doesn't it work? If you want to use a function, you just pass in both the start and end arguments after the report is opened.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 07:18
Joined
Feb 28, 2001
Messages
27,167
The basic answer is no. There is no datatype in VBA for subroutine or function entry points that you can use, and if you did, there is the problem that you would have to ALSO pass in any arguments for the function/sub that you wanted to use.

Further, passing a sub as an argument won't return a value so might trigger issues. Or perhaps the "argument not optional" IS referring to the fact that the argument returned nothing. (Not sure about that fine point.)

I've worked in languages that recognize function entries as a datatype but VBA ain't one of them.
 

Gasman

Enthusiastic Amateur
Local time
Today, 13:18
Joined
Sep 21, 2011
Messages
14,262
Managed to get it working, in the end. Thanks.
Well please show the end result, as it might help someone else? That is what this site is about after all?
 

Users who are viewing this thread

Top Bottom