Results 1 to 3 of 3
  1. #1
    4 Star Lounger
    Join Date
    Oct 2003
    Location
    Guelph, Ontario, Canada
    Posts
    428
    Thanks
    0
    Thanked 0 Times in 0 Posts

    keep focus on text box control until correct (2000 all updates)

    The form is a continuous form that keeps track of weekly donations. There are 5 different categories in which currency amounts can be entered. One of the 5 categories is Memorial.

    If an amount is entered in Memorial, then an additional text box, InMemoryOf, opens up, and an entry is supposed to be made in that text box. In addition, that entry should be a First and Last name. Below is the code that is designed to control that.

    The first piece of the code (above the - - - - -) works fine.

    The second piece of the code (below the - - - - -) works only to a point. What it checks for is the empty space that would exist between the First and Last names, and if that space isn't present the Message Box comes up. So far so good. But then, the focus goes to the next record entry. The focus does not return to Me.InMemoryOf

    Any suggestion as to how I might fix this code to achieve the desired result?

    I have tried other variations which counted the words in the "InMemoryOf" string, and the results were the same. And all I really need to know is whether or not there are two names, and if not make sure there are.

    Private Sub Form_BeforeUpdate(Cancel As Integer)
    On Error GoTo Form_BeforeUpdate_Error

    If Me.Memorial > 0 And IsNull(Me.InMemoryOf) Then
    Call MsgBox(" There is an amount in the Memorial field." _
    & vbCrLf & "Please enter a name in the ""In Memory Of"" field." _
    , vbExclamation, "Entry needed")
    Me.InMemoryOf.SetFocus
    Exit Sub
    End If
    - - - - -
    If Not IsNull(Me.InMemoryOf) Then
    Dim str As String
    Dim intTemp As Integer
    str = Me.InMemoryOf
    intTemp = InStr(Me.InMemoryOf, " ")
    If intTemp = 0 Then
    MsgBox "Please enter a First and Last name!"
    Me.InMemoryOf.SetFocus
    End If
    End If

    End Sub

    Thanks.

    Tomj

  2. #2
    4 Star Lounger
    Join Date
    Oct 2003
    Location
    Guelph, Ontario, Canada
    Posts
    428
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: keep focus on text box control until correct (2000 all updates)

    Thanks, Hans

    Worked perfectly!!!

    Tom

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

    Re: keep focus on text box control until correct (2000 all updates)

    If the record doesn't meet all requirements, you should set the Cancel argument of the event procedure to True. This prevents the record from being updated and the form from moving to the next record. So immediately below each of the MsgBox lines, insert this:

    Cancel = True

Posting Permissions

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