If ANY libraries are missing from the references, the date() function won't work. (4 Viewers)

amorosik

Active member
Local time
Today, 16:11
Joined
Apr 18, 2020
Messages
588
I'm referring to a problem I recently encountered
Discussing with some colleagues, it seems that the lack of any external references impacts the correct functionality of date-related functions
Does anyone know the reason for this strange effect?
 
If only Date() is used, the VBA library is searched last.

The search for a global function proceeds as follows:
  1. First, the VB project of the application
  2. Then the references of the VB project (excluding VBA Lib)
  3. Finally: VBA library
Quick fix:
Use VBA.Date() instead of just Date(). This eliminates the need to search the libraries.
 
This smacks of the problem that has been in Access since 97. It is the references getting out of kilter and neither recompiling nor compacting has any effect.

Open your references dialog, add any reference. Compile then remove the new ref and compile again.
 
@Josef P. :

This means the references are iterated alphabetically during runtime?
This is the first time I've heard of this, but I've never thought about it before. 🤔

Also, it doesn't seem to be tied to the VBA library, because the method "Abs" for example works fine when a reference is broken and is also only included in the VBA library...
 
This means the references are iterated alphabetically during runtime?
The order in the list of references in the dialog also depicts the priority of the references.
Moving a library, which might be potentially missing, to the lower end of the list will reduce, but not eliminate, the risk of this causing problems with functions from other libraries.

2025-07-22_13h59_54.png
 
@Josef P. :

This means the references are iterated alphabetically during runtime?
This is the first time I've heard of this, but I've never thought about it before.
As Philipp already described, in the order of the reference list - with the exception of the VBA library, which cannot be removed/moved.

Also, it doesn't seem to be tied to the VBA library, because the method "Abs" for example works fine when a reference is broken and is also only included in the VBA library...
That's interesting. Now() also works and is in the same module as Date(). Thanks for pointing that out.
Date, Time, Format or Mid do not work once a reference is broken.
I don't know why some of them work. Are they perhaps "deeper" embedded in the compiler?
We'd probably have to ask Wayne about that. But Philipp is here too. I'll pass the question on. :D

Example:
Asc will work if a reference is broken. But Asc can also be replaced by a custom function.
Code:
Public Function Asc(ByVal str As String) As Long
   Asc = VBA.Asc(str)
   Debug.Print "Asc(""" & str & """)=" & Asc
End Function
The function resolution therefore runs first via the current VBProject.
VBA is always exciting, even if it's already old. :)
 
Last edited:
If only Date() is used, the VBA library is searched last.

The search for a global function proceeds as follows:
  1. First, the VB project of the application
  2. Then the references of the VB project (excluding VBA Lib)
  3. Finally: VBA library
Quick fix:
Use VBA.Date() instead of just Date(). This eliminates the need to search the libraries.

In my case, the offending library was the last one
(the first four aren't visible in the list, but they're there; the cursor is at the bottom to show the missing library)
And no function contained in it was ever called from code
But even in this case, and therefore regardless of the loading order of the various references, the Date() function did not work as expected.

1753189605148.png
 
I would check for the possibility of a name overlap - does any other library have a Date() function? HINT: Use the VBA page's Object Browser to find Date() and see if it appears more than once. Supposedly, the search is top-down from that list of references, but I have seen some odd behavior more than just a couple of times when there was a library problem, and that odd behavior SOMETIMES resulted in a commonly referenced routine that WAS in validly referenced library nonetheless fail because of a broken link to an apparently unrelated library. In all cases, fixing the reference fixed the problem.
 
@amorosik :
Perhaps this will help you a little. You can specifically check in your startup code whether and which references are broken:

Code:
If Application.BrokenReference Then
    Debug.Print "Broken Reference(s):"

    Dim currentReference As Access.Reference
    For Each currentReference In Application.References
        If currentReference.IsBroken Then Debug.Print "- " & currentReference.Name
    Next currentReference
End If

Then your code could react accordingly before it 'crashes'.
 

Users who are viewing this thread

Back
Top Bottom