Results 1 to 8 of 8
  1. #1
    3 Star Lounger
    Join Date
    Dec 2001
    Location
    Nevada, USA
    Posts
    207
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have four variables: glbUser1Avail, glbUser2Avail, glbUser3Avail and glbUser4Avail. I would like to set glbUserXAvail = True depending on the value of the openargs passsed to the form.

    IOW:
    If openargs = "1", then
    glbUser1Avail = True
    End if

    If openargs = "2" then
    glbUser2Avail = True
    End if

    etc.

    How do I construct the variable name so I don't have to do this in four If statements?

    Hope I've made my question clear. Thanks, in advance.
    Carol W.

  2. #2
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts
    As you have framed the problem, you would need a single If with three more ElseIf cases. You could however do it as a Select Case statement something like:
    Code:
    Select Case openargs
       Case 1
    	  glbUser1Avail=True
       Case 2
    	  glbUser2Avail=True
       Case 3
    	  glbUser3Avail=True
       Case 4
    	  glbUser4Avail=Ture
       Case Else
    	  ' What ever you want to do went openargs is something else
    End Select
    If you can give us some insight into what you are trying to accomplish, we may be able to suggest other alternatives, such as using a table, turning on Access User Security, etc.
    Wendell

  3. #3
    3 Star Lounger
    Join Date
    Dec 2001
    Location
    Nevada, USA
    Posts
    207
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='WendellB' post='798579' date='17-Oct-2009 12:37']As you have framed the problem, you would need a single If with three more ElseIf cases. You could however do it as a Select Case statement something like:
    Code:
    Select Case openargs
       Case 1
    	  glbUser1Avail=True
       Case 2
    	  glbUser2Avail=True
       Case 3
    	  glbUser3Avail=True
       Case 4
    	  glbUser4Avail=Ture
       Case Else
    	  ' What ever you want to do went openargs is something else
    End Select
    If you can give us some insight into what you are trying to accomplish, we may be able to suggest other alternatives, such as using a table, turning on Access User Security, etc.[/quote]

    I was looking to construct a variable into which the value of openargs would be inserted dynamically and then use a single statement -- something like this:
    "glbUser" &openargs & "Avail" = True

    How do I construct the variable on the left side of the = sign?

    Thanks.
    Carol W.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    [quote name='WSC' post='798584' date='17-Oct-2009 21:59']"glbUser" &openargs & "Avail" = True[/quote]
    VBA doesn't let you do that.
    If you don't want to use Wendell's code, you could use an array instead of separate variables. The declaration would look like this:

    Public glbUserAvail(1 To 4) As Boolean

    And in the On Open or On Load event of the form:

    Code:
    If Not IsNull(Me.OpenArgs) Then
      glbUserAvail(Me.OpenArgs) = True
    End If
    or if you want to make sure that the others are False:

    Code:
    Dim i As Integer
    For i = 1 To 4
      glbUserAvail(i) = False
    Next i
    If Not IsNull(Me.OpenArgs) Then
      glbUserAvail(Me.OpenArgs) = True
    End If
    Instead of glbUser1Avail, you'd refer to glbUserAvail(1) etc.

  5. #5
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts
    [quote name='WSC' post='798584' date='17-Oct-2009 13:59']I was looking to construct a variable into which the value of openargs would be inserted dynamically and then use a single statement -- something like this:
    "glbUser" &openargs & "Avail" = True
    ...[/quote]
    What I should have asked is why you want to track a particular user in this fashion. Access has a reasonably sophisticated method for tracking the Current User if you activate User Security, and it is possible that would solve the issue you are working on. Your code idea seems to imply that two or more users can be active at once - but what I'm curious about is why you want to know that? Are you trying to build your own security scheme, or is it something else?
    Wendell

  6. #6
    3 Star Lounger
    Join Date
    Dec 2001
    Location
    Nevada, USA
    Posts
    207
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Wendell,

    Actually, I'm not tracking anything about a human "user".

    The application is a restaurant operation system that requires modifying to interface with a new credit card processing company and software. We wrote the application 7-8 years ago and interfaced to package A. Now the client needs it to interface to package B.

    We're using a "file drop" methodology and package B only processes transactions in a single threaded fashion. So, we essentially need to build our own queuing mechanism. The four "users" are not people; they are logins under which transactions are submitted to package B. Since there are two workstations involved, we need to know which "users" are available for processing whenever a transaction needs to be processed.

    That's it in a nutshell!

    Thanks for your interest and your replies.
    Carol W.

  7. #7
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts
    You can't do it with global variables. It could be done if instead of global variables you used checkboxes on the form (even making them hidden). Then you could have code like this: Me("chkUser" & me.openargs & "Avail) = True.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  8. #8
    3 Star Lounger
    Join Date
    Dec 2001
    Location
    Nevada, USA
    Posts
    207
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='MarkLiquorman' post='798643' date='18-Oct-2009 07:07']You can't do it with global variables. It could be done if instead of global variables you used checkboxes on the form (even making them hidden). Then you could have code like this: Me("chkUser" & me.openargs & "Avail) = True.[/quote]

    Thanks, Mark.

    You answered my real question which was whether or not a global variable name could be constructed "on the fly" via VBA code.

    The If / Else (and the Case) construction works well so I think I'll just leave it as it is.

    Thanks again.
    Carol W.

Posting Permissions

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