Results 1 to 13 of 13
  1. #1
    New Lounger
    Join Date
    Jan 2004
    Location
    Salem, Oregon, USA
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    COMMAND function (97-2003)

    I am in the process of converting a number of long-operating applications from 97 to 03. So far so good. One problem has been extensive use of the Command() function to recover command arguments on application launch. That function apparently no longer works in +2000 levels. I can work around the problem, but so far it has been awkward, involving little text files, and much fiddling about. Does anyone have an elegant solution to replace the late lamented Command()?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: COMMAND function (97-2003)

    If you start Access like this:

    "C:Program FilesMicrosoft OfficeOffice11MSAccess.exe" "C:Test.mdb" /cmd MyMessage

    the text after /cmd will be the value returned by the Command function, in this example MyMessage.

  3. #3
    New Lounger
    Join Date
    Jan 2004
    Location
    Salem, Oregon, USA
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: COMMAND function (97-2003)

    Hmmm. That's exactly the usage in our 97 applications. In the 2003 after conversion, there is no error, but the string "MyTextMessage = Command()" contains a null rather than "MyMessage." Looking up the function "Command()" in VBA help yields the line ; "This does not work in Office." Which I interpreted to mean "Access." Are you sure that Command() works in Access2003, all of my fumbling about in the de###### indicates that it doesn't. I want to emphasize that my program call is exactly as you specified.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: COMMAND function (97-2003)

    I'm using Access 2002 (XP), and it works there (I just now tested it). It should work in Access 2003 too, according to Startup command-line options.

  5. #5
    New Lounger
    Join Date
    Jan 2004
    Location
    Salem, Oregon, USA
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: COMMAND function (97-2003)

    I guess I will have to examine the code more closely to see why it isn't working. Darn, I thought I had it all figured out by blaming it on Command(). Thank you for your prompt and patient response, Hans. Best wishes. <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

  6. #6
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Sydney, Australia, New South Wales, Australia
    Posts
    251
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Re: COMMAND function (97-2003)

    Working fine in Access 2000 for me.
    Peter

  7. #7
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: COMMAND function (97-2003)

    You would use that syntax in the controlsource *property* of a textbox. Try assigning the Command() value to a variant and then use that variable to set the value of your control.
    Charlotte

  8. #8
    New Lounger
    Join Date
    Jan 2004
    Location
    Salem, Oregon, USA
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: COMMAND function (97-2003)

    Thanks Charlotte, you saved me from embarrassing myself by arguing with Hans and Peter. The variant variable is the key. I had my variable defined as String, since I "knew" the command that would be passed. (An Access Guru we hired to vet our code had been very firm about NEVER using variant definitions, which he regarded as the Spawn of The Devil.) To make a short story longer, if you write: Dim MyText As String, MyText = Command(), MyText will contain Null. Change the type to Variant, or leave out the Dim entirely, and MyText will contain the expected command. This was not the case with 97, so the appearance is that Command() does not work in 2000+ versions. Happy Holidays to you all.

  9. #9
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: COMMAND function (97-2003)

    Variants are expensive in terms of resources, but in some cases, you have no choice but to use them in VBA. This is one of those situations.
    Charlotte

  10. #10
    New Lounger
    Join Date
    Jan 2004
    Location
    Salem, Oregon, USA
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: COMMAND function (97-2003)

    I had hoped to get through this without making a fool of myself, but I guess it's not my turn. I have messed around with this for several days, and I cannot make the Command function, ... err ... function. In the attached zip file is a stripped database. The only thing that might work is the OPEN sub of the Switchboard Form. I am trying to recover the command line at launch, and stash it in an unbound text box on the switchboard form. The function Command, with or without () stubbornly returns Null if the receiving variable is typed String, and 0 if it is typed variant (or untyped). Since both Hans and Peter are confident that Command () is working, I'm sure one of you can point to where I've been stupid. The zip file also contains a text file with the command line I am using. In my opinion, if it was all working, the receiving string variable would finally contain "130" . To reiterate, it worked in Access 97, but I have been unable to get it to work in Access 2003. <img src=/S/hairout.gif border=0 alt=hairout width=31 height=23>

  11. #11
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: COMMAND function (97-2003)

    I suspect that your Switchboard form is corrupt in some way. Although the DistrictUnitNumberFromCommandLine text box displays the Command value correctly for me, the message box doesn't. If I create a new form in your database and copy the message box instruction into its On Open event, it does work correctly. So you will have to re-create your switchboard form.

  12. #12
    New Lounger
    Join Date
    Jan 2004
    Location
    Salem, Oregon, USA
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: COMMAND function (97-2003)

    May I beg a favor? I have tried several different ways to make this work. I wonder if there is something about my installation of A2003 that is corrupting or altering my database. Could you attach a database that contains the form you just referenced, so I can see it run in my own environment? Maybe there's a subtle syntax problem that will show up head-to-head. Thanks for all the support you have given.

  13. #13
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: COMMAND function (97-2003)

    I have added a form to your database (frmTest).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •