undefined expression error (1 Viewer)

omarrr128

Member
Local time
Today, 06:47
Joined
Feb 5, 2023
Messages
69
Whenever i open my access frontend i get an error that there is an undefined expression called "fnElapsed".

this is the module code. can anyone see where the error is coming from?


Public Function fnElapsed(ByVal start_time As Variant, ByVal end_time As Variant, ByVal job_is_finished As Boolean) As Variant
Dim Elapsed
fnElapsed = Null
If Not IsDate(start_time) Then
Exit Function
End If
If job_is_finished Then
Elapsed = end_time - start_time

Else
Elapsed = Now() - start_time

End If
fnElapsed = Format$(Elapsed, "hh:nn")
End Function

thank you
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 00:47
Joined
Feb 28, 2001
Messages
27,191
Just to clarify... if you open the FE before attempting anything else - like manually opening some form or report - you get the indicated error. I would presume that after the error is announced, the DB then starts up in a state ready for exploration and development. If it exits, you've got a bigger problem that will require a bit more effort.

There is a possibility that there is something wrong with the code, but I don't see it at the moment. But the question is, what EXACTLY does the error say (including any error number)? If it triggers the pop-up box that gives you the option to debug it, does Access highlight a line of code? When it shows the error, does it automatically go to a line of code and highlight it yellow? If you got the debug option and click it, does THAT highlight a line of code?

Thinking out loud here, if my first assumption is correct (happens immediately at startup), either an autoexec macro or a startup form somehow references fnElapsed. You need to find where it is referenced because syntactically, it looks OK - but the semantics of it could be a problem in the place it was called.

If this is called from an autoexec macro, the question would be whether you can put a breakpoint on the first executable line of the function - which is fnElapsed = Null - and if so, does it take the breakpoint on a startup attempt?

If this is a startup form, the offending reference would probably be in the Form_Open event, Form_Load event, or Form_Current event. So find the place where this function is called and put a breakpoint on line making the call.

Now if either of those suggestions leads you to successfully taking the breakpoint, single-step it and note where it bombs out on you. I'm kind of leaning to the idea that in your startup code, if the argument start_time is not right, you are going to return a null as the value of fnElapsed, and something that called fnElapsed will complain.

It would probably help if you can find where fnElapsed is called to verify that you are giving it the data you expected. Also, I don't know what your data would resemble, but that line that reads: fnElapsed ] Format$( Elapsed, "hh:nn" ) has a problem if Elapsed ever spans greater than one day.
 

isladogs

MVP / VIP
Local time
Today, 06:47
Joined
Jan 14, 2017
Messages
18,235
As Doc said look for instances of the function being called in startup code
As written all arguments are required which is illogical if the final argument is false

Modified version of your code with two optional arguments and scrapping all variants:

Code:
Public Function fnElapsed(start_time As Date, Optional end_time As Date, Optional job_is_finished As Boolean = False) As String

Dim Elapsed As Date

If Not IsDate(start_time) Then
    Exit Function
End If

If job_is_finished Then
    Elapsed = end_time - start_time
Else
    Elapsed = Now() - start_time
End If

fnElapsed = Format$(Elapsed, "hh:nn")

End Function


Example output

Code:
?fnElapsed(#5:32:00 AM#, #7:34:00 AM#, True)
02:02

?fnElapsed


?fnElapsed(#4:45:00 AM#, , False)
04:35

?fnElapsed(#4:45:00 AM#)
04:35
 

Users who are viewing this thread

Top Bottom