Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Nov 2004
    Location
    Lexington Park, Maryland, USA
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Variable used in a Form Expression (Access 2000)

    Why am I getting the following error when I use this bit of code. The variable evaulates correctly.

    for i = 1 to 8
    dim dd_parameter = "dd_Parameter_" & i
    Forms![Search].[" & dd_parameter & "].Value = "[0-z]*"
    next i

    Run-time error '2465'
    Can't find the Field "|" referred to in your expression.

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

    Re: Variable used in a Form Expression (Access 2000)

    Dim is used to declare a variable, not to assign it a value. You must declare and assign in separate instructions. Moreover, you cannot refer to a control (I assume that that's what you want to refer to, lacking any explanation in your post) the way you try to do it. You can use the Controls collection of the form.

    Maybe this:

    Dim dd_parameter As String
    For i = 1 To 8
    dd_parameter = "dd_Parameter_" & i
    Forms!Search.Controls(dd_parameter).Value = "[0-z]*"
    Next i

  3. #3
    2 Star Lounger
    Join Date
    Nov 2004
    Location
    Lexington Park, Maryland, USA
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Variable used in a Form Expression (Access 2000)

    Thanks Hans,

    Today has been one of those days. I knew everything you suggested. I have done that before many times. THe hole thing with dimensioning the variable and assigning a variable in a single line was a major typo. I really am a better programmer than it might seem with some of my questions. Your suggestions worked perfectly, as usual.

    Mike

Posting Permissions

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