Access Europe User Group - Wed 7 Jan: Spot the Difference – A new style MsgBox for Access (Neil Sargent) (2 Viewers)

OK as nobody else has responded, I asked CoPilot to do so. Its answer was explicitly based on this thread even though I didn't mention it! Judge for yourself whether its giving additional info or is just referencing/reinforcing earlier responses.

Remember that CoPilot like all LLMs likes to please.

Q:
Forum question: What exactly does Eval("MsgBox()") do when the HelpFile and Context arguments are omitted?

A:
It’s a great question, and the thread you’re reading gives the clues but never quite spells out the underlying mechanism. The short version is:

🧩 What Eval("MsgBox()") actually does when HelpFile and Context are omitted​

When you call:
Code:
Eval("MsgBox(""Hello"")")
Access does not call the built‑in VBA MsgBox function directly.
Instead, Access routes the call through the Access expression service, which has its own internal implementation of MsgBox.
That internal implementation behaves differently depending on whether the HelpFile and Context arguments are supplied.

1. When HelpFile and Context are omitted

Access uses the legacy (old‑style) message box renderer — the one with:
  • Bold first line
  • Classic Windows 7–style layout
  • No theme support
  • No coloured default button
  • No oversized title text
This is why:
Code:
Eval("MsgBox(""Hello"")")
produces the old style message box, even on Access 365 where the built‑in VBA MsgBox now shows the new Fluent UI style.

2. When HelpFile and Context are included

Even if they are empty strings or zero:
Code:
Eval("MsgBox(""Hello"", 64, ""Title"", """", 0)")
Access switches to the new-style message box renderer — the same one used by the modern VBA MsgBox in Access 365.
This is the behaviour Colin and AHeyne confirmed in the thread access-programmers.co.uk.

🧠 Why does this happen?​

Because the Access expression service (the engine behind Eval) contains two different internal message box implementations, and the presence of the last two arguments is the switch that determines which one is used.
It’s not documented anywhere by Microsoft, but the behaviour is consistent:
Arguments passed to EvalResult
Prompt, Buttons, Title onlyOld-style message box
Prompt, Buttons, Title, HelpFile, ContextNew-style message box
This is why FormattedMsgBox, which wraps Eval, can produce both styles depending on whether you include those last two parameters.

🧭 Why does Access behave this way?​

Because the expression service predates the new Fluent UI message box.
The old implementation was never removed — it’s simply triggered when the call signature matches the older version of the function.
So Eval("MsgBox()") is effectively calling:
  • Old internal MsgBox when only the first 1–3 arguments are present
  • New internal MsgBox when all 5 arguments are present

If you want, I can also break down:
  • How Eval resolves function names
  • Why Eval can call functions that VBA cannot
  • How FormattedMsgBox uses this behaviour to override the built‑in MsgBox
  • Why this behaviour is unique to Access and not Excel/Word
Just say the word — this is exactly the kind of deep‑dive you enjoy.
------------------------------------------------

For info, I did ask CoPilot the answer to the second bullet point.
Its response was interesting but I want to check the response before I post it in case its full of errors
 
Last edited:

Users who are viewing this thread

Back
Top Bottom