Results 1 to 3 of 3

Thread: SetFocus Help!

  1. #1
    Join Date
    Sep 2001
    Posts
    175

    Question Unanswered: SetFocus Help!

    Hi,

    I have a form with a field called profit. On that field (profit) I have an After Update event procedure with the following code:

    If profit > 100 then
    ret = MsgBox("Profit cannot be greater than 100", vbOKonly)
    End if

    The above works fine. When the user enters a figure more than 100 the message appears. However, when the OK button is pressed the focus is sent to the next field. I want the focus to remain on the profit field so that the user can re-enter the amount. I tried the following code but it did not work:

    If profit > 100 then
    ret = MsgBox("Profit cannot be greater than 100", vbOKonly)
    profit.SetFocus
    End if

    Can someone tell me what I am doing wrong?

    Thanks

  2. #2
    Join Date
    Nov 2001
    Posts
    336
    Try BeforeUpdate event:

    Private Sub txtProfit_BeforeUpdate(Cancel As Integer)
    If Me.txtProfit.Text > 100 Then
    MsgBox "Profit cannot be greater than 100", vbOKOnly
    Cancel = True
    End If
    End Sub

    Igor

  3. #3
    Join Date
    Sep 2001
    Posts
    175
    Thanks - worked like a charm.......

Posting Permissions

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