using a variable as part of the reference path

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • waltvw
    New Member
    • Jun 2007
    • 7

    #1

    using a variable as part of the reference path

    I'm trying to set up a value for a control on the report and part of the path should be a variable, since I have multiple objects like that. So when I try to put a variable I'm getting the "Compile Error: Syntax Error" message and don't know how to handle it.

    Reports!rptFlgT est!"& strFieldName &" = -1

    I've tried to put single quotes around double ones as well as not to use any; or not to use ampersands while having either single quotes or double ones or both and nothing worked! In the hardcoded version, however, i.e. when the actual name of the check box on the report is hardcoded in the path, like

    Reports!rptFlgT est!CheckBox1 = -1

    the code compiles and assigns a value to the control like it is expected.

    Anybody knows what syntax I should use for a variable?
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Originally posted by waltvw
    ...
    Reports!rptFlgT est!CheckBox1 = -1
    ...
    Anybody knows what syntax I should use for a variable?
    Generally speaking, the controls will be in the Controls collection, where you should be able to use a string to refer to them by name. So for example, I think (not positive) that in the above code you could have used Reports!rptFlgT est.Controls("C heckBox1") = -1
    If that works, then of course it follows that you can use a variable in place of the string.

    Comment

    • waltvw
      New Member
      • Jun 2007
      • 7

      #3
      Originally posted by Killer42
      Generally speaking, the controls will be in the Controls collection, where you should be able to use a string to refer to them by name. So for example, I think (not positive) that in the above code you could have used Reports!rptFlgT est.Controls("C heckBox1") = -1
      If that works, then of course it follows that you can use a variable in place of the string.
      Thanks for the response. Right after I posted my question I found an answer to it, which was putting my string variable in parenthesis:
      Reports!rptFlgT est!(strFieldNa me) = -1

      In fact, I went 1 step further and eliminated the variable, putting a path to a field returned by SQL statement in parenthesis:

      Dim rsttblFlags As Recordset

      strSQL = 'some SELECT St-t here that retrieves rows from a MS Access table'.
      Set rsttblFlags = dbs.OpenRecords et(strSQL)
      Reports!rptFlgT estSingleCusip! (rsttblFlags!Fi eldName) = -1

      Thanks again for your help!

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        Originally posted by waltvw
        Thanks for the response. Right after I posted my question I found an answer to it, which was putting my string variable in parenthesis:
        Reports!rptFlgT est!(strFieldNa me) = -1
        ...
        Glad to see you got it working.

        As a matter of fact, that's pretty much the same thing I did, you simply allowed it to take the default collection (Controls) while I included it, because I didn't know for sure whether it was the default.

        Comment

        Working...