1

MS Access (2007 - 2016) in Office 365

I'm trying/failing to capture a value passed into Access from the command line using the Command() function in a Macro. THis is the macro that I created with the wizard...

If Command()="Update_Burndown_Metrics" Then
  RunSQL
    SQL Statement   insert .... blah, blah
End If

No error when I save the macro, but when I run...

The expression you entered has a function name that Microsoft Access can't find

If I replace the...

If Command()="Update_Burndown_Metrics" 

with

If 1=1

It runs fine. IOW, it's not the SQL. It's the "Command() function that it can't find.

I got the idea to use Command() from Opening Microsoft Access with parameters . Doesn't seem to work for me. But that coding approach is also confirmed here... http://www.utteraccess.com/wiki/Command-Line_Switches . So I think it's something else.

Eventually, I would like to pass the Update_Burndown_Metrics arg using /cmd on the command line.

Why can't it find Command() as a valid function ? Is it a scoping thing? Do I have to give Command() context somehow, maybe with some sort of prefix ?

daveg
  • 1,051
  • 11
  • 24

2 Answers2

0

I can't seem to reproduce the issue that you are describing, though, I am using an earlier version of MS Access, and so there may be some differences in the behaviour of this function.

The Command function should be globally accessible, even outside of VBA (it can be referenced by the ControlSource property of a text box, for example), and so this isn't an issue of scope.

I do observe from the Office 365 documentation, that the Command function is being invoked without the use of parentheses in the sample VBA Sub provided; therefore it may be worth you trying your code without including such parentheses, e.g.:

If Command = "Update_Burndown_Metrics" Then
    MsgBox "Test succeeded."
Else
    MsgBox "Test failed."
End If
Lee Mac
  • 15,615
  • 6
  • 32
  • 80
0

The workaround I created is to create a function in vba that gets and returns the command...

Public Function GetCommand() As String
  GetCommand = Command()
End Function

Then...

If GetCommand() = "Update_Burndown_Metrics" Then ...
daveg
  • 1,051
  • 11
  • 24