Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validation 1

Status
Not open for further replies.

OceanBlue

IS-IT--Management
Aug 15, 2002
54
0
0
US
I have this validation code behind the sumit command button

Code:
On Error GoTo Err_cmdSubmit_Click
    
    If IsNull(Approval) Then
        MsgBox "Approval must be entered before you can submit the record.", vbCritical, "Invalid Save"
        cboTO.SetFocus
    ElseIf IsNull(Type) Then
        MsgBox "Type must be entered before you can Submit the record.", vbCritical, "Invalid Save"
        cboJobType.SetFocus
    ElseIf IsNull(Effort) Then
        MsgBox "Effort must be entered before you can Submit the record.", vbCritical, "Invalid Save"
        cboJobType.SetFocus
 
   Else
    'Save the record
     DoCmd.RunCommand acCmdSaveRecord
    'Requery the listbox
     Me.WorkLst.Requery
    'Notify user log submitted
    'MsgBox "Work Log Entry Submitted", vbOKOnly + vbInformation, "Log Sumitted"
    'Close the form
   ' DoCmd.Close acForm, Me.Name
    End If
    
Exit_cmdSubmit_Click:
    Exit Sub

Err_cmdSubmit_Click:
    MsgBox Err.Description
    Resume Exit_cmdSubmit_Click

The validation portion is not working. If the Type or Effort IsNull it is going ahead and saving the record and closing. I'm not get the Msg Box.
 
I need to modify this post. In the above post I have most of the things commented out for testing purposes.

Below is the Correct Code
Code:
On Error GoTo Err_cmdSubmit_Click
    
    If IsNull(Approval) Then
        MsgBox "Approval must be entered before you can submit the record.", vbCritical, "Invalid Save"
        cboTO.SetFocus
    ElseIf IsNull(Type) Then
        MsgBox "Type must be entered before you can Submit the record.", vbCritical, "Invalid Save"
        cboJobType.SetFocus
    ElseIf IsNull(Effort) Then
        MsgBox "Effort must be entered before you can Submit the record.", vbCritical, "Invalid Save"
        cboJobType.SetFocus
 
   Else
    'Save the record
     DoCmd.RunCommand acCmdSaveRecord
    'Requery the listbox
     Me.WorkLst.Requery
    'Notify user log submitted
     MsgBox "Work Log Entry Submitted", vbOKOnly + vbInformation, "Log Sumitted"
    'Close the form
     DoCmd.Close acForm, Me.Name
    End If
    
Exit_cmdSubmit_Click:
    Exit Sub

Err_cmdSubmit_Click:
    MsgBox Err.Description
    Resume Exit_cmdSubmit_Click
 
You may try to replace each:
If IsNull(SomeControl) Then
with something like this:
If Trim(SomeControl & "") = "" Then

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top