Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2004
    Posts
    36

    Unanswered: Variables in SetFocus statement

    Hi. I'm writing a bunch of edits for a form the users enter data into. Whenever an edit is incurred, the code moves the cursor to the field in error. Some of these fields are in subforms, so I use the code ...

    Forms!frmreview![MYHH subform].SetFocus
    Forms!frmreview![MYHH subform].Form.[Type of Income 1].SetFocus

    to move to the field "Type of Income 1" for example.

    What I want to do is use a variable for the field [Type of Income 1] entry. The field names are "Type of Income 1", "Type of Income 2", etc.

    Is this possible? I"ve tried variations but none have worked so far.

    Here's one of many tries that didn't work:
    ------------------------------
    Select Case rs(j)
    Case 2: thefield = "[Type if Income 1]"
    Case 4: thefield = "[Type if Income 2]"
    Case 6: thefield = "[Type if Income 3]"
    Case 8: thefield = "[Type if Income 4]"
    End Select

    Forms!frmreview![MYHH subform].SetFocus
    Forms!frmreview![MYHH subform].Form.thefield.SetFocus

    ------------------------------

    TIA

  2. #2
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    Try something like this:

    Forms!frmreview("type of income" & x).SetFocus
    Inspiration Through Fermentation

  3. #3
    Join Date
    Aug 2004
    Posts
    36
    Quote Originally Posted by RedNeckGeek
    Try something like this:

    Forms!frmreview("type of income" & x).SetFocus
    No, that didn't work. But thanks for playing.

  4. #4
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    Then you're doing something wrong

    From what I can see of your code, this would work...

    Forms!frmreview![MYHH subform].Form(theField).SetFocus

    or this:

    Forms!frmreview![MYHH subform].Form("type of income " & rs(j)/2).SetFocus
    Inspiration Through Fermentation

  5. #5
    Join Date
    Aug 2004
    Posts
    36
    Quote Originally Posted by RedNeckGeek
    Then you're doing something wrong

    From what I can see of your code, this would work...

    Forms!frmreview![MYHH subform].Form(theField).SetFocus

    or this:

    Forms!frmreview![MYHH subform].Form("type of income " & rs(j)/2).SetFocus
    Naw, I just tried both of those again. I get the message:

    Error Number 2465: Microsoft Access can't find the field '|' referred to in your expression. :qctest

    I'm wondering if it has something to do with the brackets. When I try to take the brackets out, the line of code turns red. When I put them back, it's fine.

    I tried putting the variable within brackets and I get the same message. Are the brackets necessary because there are spaces in the field name? I came from the Paradox/ObjectPal world where you could insert underscores between words in a field name in those situations and you wouldn't need parens. Does Access have anything like that?

Posting Permissions

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