Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Apr 2001
    Posts
    122
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Variable Name Syntax

    I am trying to use a Global variable in an OpenForm command as the source of the value to be searched for, e.g. DoCmd.OpenForm "xyz",,"[Global Variable] = [Search Key]". I have tried the variable name with and without brackets and neither works.

  2. #2
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    USA
    Posts
    386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Variable Name Syntax

    You need an additional comma.

    Try DoCmd.OpenForm "xyz",,,"[Global Variable] = [Search Key]".


    Richard Aheron
    raheron@hotmail.com
    Richard

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

    Re: Variable Name Syntax

    OK, if the Global Variable is Global Variable, what does [Search Key] represent? You can't have a space in a variable name, so assuming that Global Variable is NOT the name of the variable, you could try this:

    DoCmd.OpenForm "xyz",,,"[" & GlobalVariable & "]=SearchKey"

    However, if Search Key is also a variable, you would have to concatenate it as well as the global variable and put it on the outside of the quote.
    Charlotte

  4. #4
    2 Star Lounger
    Join Date
    Apr 2001
    Posts
    122
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Re: Variable Name Syntax

    Thank you for responding to a poorly formed question. Based on your suggestions, I tried the following code that actually seems to work in Access 2000:

    DoCmd.OpenForm "Edit IPC", , , [lastIPCKEY] & " = [IPC KEY]", acFormReadOnly

    lastIPCKEY is a Global Variable, IPC KEY is a data element in the table attached to the form Edit IPC.

    Now I need to get the same function to work in Access 2. I tried the following code:

    DoCmd OpenForm "Edit IPC", , , [lastIPCKEY] & " = [IPC Key]", A_READONLY

    but I get a compile error message : Invalid Object Reference that refers to [lastIPCKEY]. Obviously there is some syntax difference between A2 and A2000 that I am missing.

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

    Re: Variable Name Syntax

    I don't know why it worked in Access 2000 either. Here's the syntax that should work in all versions:

    DoCmd OpenForm "Edit IPC", , , "[" & lastIPCKEY & "] = [IPC Key]", A_READONLY
    Charlotte

Posting Permissions

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