Results 1 to 7 of 7
  1. #1
    Join Date
    Aug 2004
    Location
    Cinci, OH
    Posts
    49

    Unanswered: help with setfocus

    Hey all,

    I am using this code:


    Private Sub Status_LostFocus()
    'doublechecks the selection on the status window

    If IsNull(Status.Value) Then
    MsgBox ("Select a status")
    End If
    Me!Status.SetFocus

    End Sub

    But the focus is not going back to the Status field. Is there something else that should be there?

    Thanks.
    Richard.

  2. #2
    Join Date
    Apr 2003
    Location
    Alabama, USA
    Posts
    154
    Try changing me!Status to me.Status
    Code:
    Private Sub Status_LostFocus()
     
    'doublechecks the selection on the status window
    If IsNull(Status.Value) Then 
     
    MsgBox ("Select a status") 
    Me.Status.SetFocus
     
    End If 
     
    End Sub
    Are you trying to set the focus only if IsNull(Status.Value) = True? The way you have it will set focus to Status whenever Status loses its focus.

    I am wondering if there might be a problem with your field name being a reserved word? Try renaming the control something else and changing your code accordingly to see if that works?

    Is your filename Status.mdb?
    http://AccessDB.Info

    You live and learn. At any rate, you live. - Douglas Adams

  3. #3
    Join Date
    Dec 2003
    Location
    Dallas, TX
    Posts
    1,004
    Hi Richard,

    Is "STATUS" a TextField or a ComboBox? I would think you would place that code in the AfterUpdate event. After whatever action takes place in the Status field, if it happens to be a null then return the focus there. Generally this takes places AFTER the user does something. How does the Status field change? ComboBox selection? Typing in a value?

    Bud

  4. #4
    Join Date
    Aug 2004
    Location
    Cinci, OH
    Posts
    49
    I am using a combo box to update this field. When the record loads it has the focus and I don't want anyone to leave that field with out selecting somthing from the drop down list.

    Thanks for any assistance.

    Richard.

  5. #5
    Join Date
    May 2004
    Posts
    159
    Can't you just set the property of that field to required? Once someone sets focus on it it won't let you leave without entering data.

  6. #6
    Join Date
    Dec 2003
    Location
    Dallas, TX
    Posts
    1,004
    Quote Originally Posted by WilliamS
    Can't you just set the property of that field to required? Once someone sets focus on it it won't let you leave without entering data.
    I second that what WilliamS said. That will also generate the default Access error message letting them know something is required in order to move on.

    Bud

  7. #7
    Join Date
    Jun 2004
    Location
    Florida, US
    Posts
    521
    I also recommend doing it in table level, it is more safe. though control's Validate Rule Property would be usefull too, if you want to give a specific message to user.

    Code:
    in Propertybox of control:
    Validate Rule= is not null
    Validate Text= "This field cannot be null."
    ghozy.

Posting Permissions

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