Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2003
    Posts
    292

    Unanswered: onclick .. checking blank fields

    I have a field "strProject" that the user needs to fill in .. What I want is for if the field is blank and the user hits a submit button .. a message pops up.. " You need to fill in field strProject ! " if the field is filled in then fine .. submit record...

    how do you do that?

    thanks

  2. #2
    Join Date
    Nov 2002
    Location
    Wyoming
    Posts
    48
    Hi:

    Try the following code in the OnClick event of your submit button:

    If Me!strProject = "" Then
    MsgBox("You need to fill in field strProject !")
    Me!strProject.SetFocus
    Else
    Put the code to submit the record here.
    End If

    I'm sure there are other ways to do this, but this should work.
    Cheers,
    Ken

  3. #3
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713

    Re: onclick .. checking blank fields

    Originally posted by TonyT
    I have a field "strProject" that the user needs to fill in .. What I want is for if the field is blank and the user hits a submit button .. a message pops up.. " You need to fill in field strProject ! " if the field is filled in then fine .. submit record...

    how do you do that?

    thanks
    Here is how I handle this issue:

    Code:
    Function FieldValidations() As Boolean
        Dim ErrorMsg As String
        Dim AllIsOK As Boolean
        
        AllIsOK = True
        ErrorMsg = ""
        
        If StatusComboBox.Value & "" = "" Then
            AllIsOK = False
            ErrorMsg = "The status is not selected." & vbCrLf
        End If
        If FirstNameTxt.Value & "" = "" Then
            AllIsOK = False
            ErrorMsg = ErrorMsg & "The first name is missing." & vbCrLf
        End If
        If LastNameTxt.Value & "" = "" Then
            AllIsOK = False
            ErrorMsg = ErrorMsg & "The last name is missing." & vbCrLf
        End If
        If SSN_Txt.Value & "" = "" Then
            AllIsOK = False
            ErrorMsg = ErrorMsg & "The SSN # is missing."
        End If
        If DeptComboBox.Value & "" = "" Then
            AllIsOK = False
            ErrorMsg = "The department is not selected." & vbCrLf
        End If
    '    If BillingTxt.Value & "" = "" Then
    '        AllIsOK = False
    '        ErrorMsg = ErrorMsg & "The billing rate is missing."
    '    End If
        
        If Not AllIsOK Then MsgBox ErrorMsg, vbCritical, "System Monitor"
        FieldValidations = AllIsOK
    End Function
    And then all I do is make a call in the OnClick event to this function ... Ex:

    ' Validations ...
    If Not FieldValidations Then Exit Sub

  4. #4
    Join Date
    Jul 2003
    Posts
    292
    Thanks guys..

    I will try them both

Posting Permissions

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