• Form’s fields (Access97)

    Author
    Topic
    #376656

    How do I in “Forms”, after I use a control button “Add Record”, have the cursor
    automatically move to a desired field for data entry? Presently, I have to move
    up to it to enter data.

    The second question, is it possible to have calculated fields change text color
    if they exceed a particular range? If so, how and where does one specify the
    desired range and then the putting of the two together? Presently I have the
    calculated fields working fine.

    All help is appreciated..

    Viewing 2 reply threads
    Author
    Replies
    • #617626

      If you add the new record using vba, you can include the line
      me!controlname.setfocus, where controlname is the name of the control you want to move to.

      I think you can do the same thing with a macro, but I forget.

      Access 2000 introduces conditional formatting exactly for what you want.
      In 97 you would have to write code in the after update event for the controls that contribute the data to the calulated field, ( and also in the oncurrent event for the form) to set the colour of the calculated field. This would work OK on a single form, but not on a continuous form because all occurrences of the field would all change at the same time.

      • #617639

        John,

        Thank you for such a speedy reply. I won’t get a chance to try it till Wednesday at work, I appreciate it very much, I have been struggling with for a couple of days now.

    • #617662

      Your question:
      <>

      What I would do here, is while in design view of the form, seelct View and Tab Order, this way you can specify the order of the controls on the form.

      As to your second question, John’s idea is ok for this.

      HTH
      Pat cheers

      • #617907

        I agree that setting the tab order would usually do the same job. There are times however when I want to set the focus to a control that is not first in the tab order, and setfocus allows you to put the focus anywhere you like.
        Sometimes you can put values into some fields using code, and so you want to set the focus to the first blank field.

        • #617990

          Watch out for code that tries to use setfocus on the control that already has the focus though.

          • #618010

            I wasn’t aware of this problem.
            I have just been trying it out, and it seemed to just ignore the setfocus command, and move the next control.
            Is this all that happens or does it cause more serious problems?

    • #618315

      Thanks everyone for your help, I wish I had of thought of using this before.
      The setfocus worked great for moving the cursor up to the desired field. Thanks….. I had previously tried the tab order but the cursor would stay on the “Add Record” button.
      I was also able to get the data to change text as desired using code, but now I keep getting -” Run-time Error “13” – Type Mismatch”. I am looking at one field and upon it’s change, calculating to a “%” in another field. Is this my problem?

      • #618319

        Can you post the code you are using.
        Not sure what you mean by ” calculating to a “%” in another field” ?

        • #619053

          Private Sub Slurry_Weight_AfterUpdate()
          Dim lngRed AS Long, lngWhite As Long
          Dim pct_slurry As String

          Me.Slurry.Enabled = True
          Me.Slurry.SetFocus
          pct_slurry=Me.Slurry.Text
          Me.Slurry_Weight.SetFocus
          Me.Slurry.Enabled=False

          lngRed= RGB(255, 0 ,00
          lngWhite=RGB(255, 255, 255)
          If CSng(Left$(pct_slurry, Len(pct_slurry) – 1)) < 12 then (this is where the error is.)
          Me.Slurry.ForeColor = lngRed

          I did not include all the script, but hopefully this helps. Thanks in advance.

    Viewing 2 reply threads
    Reply To: Form’s fields (Access97)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: