Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Jun 2002
    Location
    Nottingham, Nottinghamshire, United Kingdom
    Posts
    257
    Thanks
    0
    Thanked 0 Times in 0 Posts
    In my database I have defined a global variable 'gstrSubsYear'. I can check that it is initialising correctly by putting a text box on a form and setting it to gstrSubsYear in the form's OnOpen event.

    I am trying to use it on a report by having a text box's control source property set to '="Year to April " & gstrSubsYear'. Access pops up a parameter box asking for gstrSubsYear and has converted & gstrSubsYear into [gstrSubsYear].

    I thought I knew about concatenation of strings but have never come across this behaviour before. How do I get the field to recognise the global variable?

    Regards

    David

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    You can use global variables in VBA code but not in queries and in expressions such as the control source of a text box.

    To get around this, create a function in a standard module that returns the value of the variable:

    Code:
    Public Function GetSubsYear() As String
      GetSubsYear = gstrSubsYear
    End Function
    You can use it like this:

    ="Year to April " & GetSubsYear()

  3. #3
    3 Star Lounger
    Join Date
    Jun 2002
    Location
    Nottingham, Nottinghamshire, United Kingdom
    Posts
    257
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Many thanks Hans. I hadn't come across that limitation before.

    Regards
    David

Posting Permissions

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