Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2002
    Location
    Island of Dots
    Posts
    316

    Unanswered: Problems validating

    I have a main form (frmMain) and within it a subform (fsubDetails). Each are based on a separate query. Once a record has been created and the focus is on fsubDetails, I want to validate two fields within fsubDetails, and until these conditions have been met, I don't want the user to be able to move focus back to frmMain. The two fields within fsubDetails are:

    txtNumber; txtAddress;

    Both must have data entered into them. If they are Null (once a new record has been created in fsubDetails), then the focus can not go beyond fsubDetails.

    With that in mind, I have the following code on fsubDetails BeforeUpdate Event Procedure:

    If IsNull(txtNumber) Then
    MsgBox "Number field can not be left blank."
    txtNumber.SetFocus
    End
    ElseIf IsNull(txtAddress) Then
    MsgBox "Address can not be left blank."
    txtAddress.SetFocus
    End
    End If

    The problem I have, is that once I prompt a message caused by leaving txtNumber or txtAddress blank (Null), I am then allowed to change focus to frmMain. This isn't what I want to be happening - I need the focus to stay within fsubDetails until the user enters data into txtNumber and txtAddress. Its probably so simple, its staring me in the face, but if anyone can see where I am going wrong I would greatly appreciate your help.

  2. #2
    Join Date
    Aug 2002
    Location
    Syria
    Posts
    4
    Hi,

    you can Define a boolean variable (fasle or true) in the form general declaration area.
    Dim ChkAddress as Boolean
    Dim ChkNumber as Boolean
    and then, in your code : it should look like the following:

    If IsNull(txtNumber) Then
    MsgBox "Number field can not be left blank."
    ChkNumber =Fasle
    txtNumber.SetFocus
    Else
    chknumber =true
    end if

    If IsNull(txtAddress) Then
    MsgBox "Address can not be left blank."
    ChkAddress = Flase
    txtAddress.SetFocus
    else
    chkAddress =true
    End If

    in the LostFocus event: do the following
    Example:

    if chkAddress= false then
    txtaddress.setfocus


    and so for the number

    I hope this would be what you want

    Regards,

    Osheikha

Posting Permissions

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