cmd buttons issue

sorry I don't have that much experience writing code. This is partly what I came up wih. Is there a way I can get rid of this save button and just use New Call. I really appreciate the help

Private Sub Add_Record_Click()
On Error GoTo Err_Add_Record_Click
If Me.cmdSave.Caption = "Save" Then
Me.Add_Record.Caption = "New Call"

' ... Validation code GOES HERE ...
If IsNull(Me.CS_Rep) Then
MsgBox "CS Rep Is Required"
Me.CS_Rep.SetFocus
Else
If IsNull(Me.CALLERS_NAME) Then
MsgBox "Callers Name Is Required"
Me.CALLERS_NAME.SetFocus
Else
If IsNull(Me.Caller_Type) Then
MsgBox "Caller's Type Is Required"
Me.Caller_Type.SetFocus
Else
If IsNull(Me.FOLLOW_UP) Then
MsgBox "Please enter Y or N for Follow Up"
Me.FOLLOW_UP.SetFocus
Else
If IsNull(Me.NOTE1_subform) Then
MsgBox "Note Needed"
Me.NOTE1_subform.SetFocus
Else
End If
End If
End If
End If
End If
End If
End If
End If
If ValidationIsFine Then
' ... Save code here GOES HERE ...
End If
Else
Me.cmdSave.Caption = "Save"
' ... Validation code GOES HERE ...
If ValidationIsFine Then
DoCmd.GoToRecord , , acNewRec
End If
End If

Exit_Add_Record_Click:
Exit Sub

Err_Add_Record_Click:
MsgBox Err.Description
Resume Exit_Add_Record_Click


End Sub
 
Code:
Private Sub Add_Record_Click()
On Error GoTo Err_Add_Record_Click
    If Me.cmdSave.Caption = "Save" Then
        Me.Add_Record.Caption = "New Call"
 
        ' ... Validation code GOES HERE ...
           If IsNull(Me.CS_Rep) Then
        MsgBox "CS Rep Is Required"
        Me.CS_Rep.SetFocus
        Else
        If IsNull(Me.CALLERS_NAME) Then
            MsgBox "Callers Name Is Required"
            Me.CALLERS_NAME.SetFocus
            Else
            If IsNull(Me.Caller_Type) Then
                MsgBox "Caller's Type Is Required"
                Me.Caller_Type.SetFocus
                Else
                If IsNull(Me.Agency_Codes) Then
                    MsgBox "Agency Code Is Required"
                    Me.Agency_Codes.SetFocus
                    Else
                    If IsNull(Me.Reason_Codes) Then
                        MsgBox "Reason Code Is Required"
                        Me.Reason_Codes.SetFocus
                        Else
                        If IsNull(Me.ACCOUNT_) Then
                            MsgBox "Account # Is Required"
                            Me.ACCOUNT_.SetFocus
                            Else
                            If IsNull(Me.FOLLOW_UP) Then
                                MsgBox "Please enter Y or N for Follow Up"
                                Me.FOLLOW_UP.SetFocus
                                Else
                                If IsNull(Me.NOTE1_subform) Then
                                    MsgBox "Note Needed"
                                    Me.NOTE1_subform.SetFocus
                                    Else
                              End If
                            End If
                        End If
                    End If
                End If
            End If
        End If
    End If
        If ValidationIsFine Then
            ' ... Save code here GOES HERE ...
        End If
    Else
        Me.cmdSave.Caption = "Save"
        ' ... Validation code GOES HERE ...
        If ValidationIsFine Then
            DoCmd.GoToRecord , , acNewRec
        End If
    End If
 
Exit_Add_Record_Click:
    Exit Sub
 
Err_Add_Record_Click:
    MsgBox Err.Description
    Resume Exit_Add_Record_Click
 
 
End Sub
 
Here's your validation code:
Code:
Public Function ValidationFailed() As Boolean
    ' Validate required fields
    If Len(Me.CS_Rep & vbNullString) = 0 Then
        MsgBox "CS Rep Is Required"
        Me.CS_Rep.SetFocus
        ValidationFailed = True
    ElseIf Len(Me.CALLERS_NAME & vbNullString) = 0 Then
        MsgBox "Callers Name Is Required"
        Me.CALLERS_NAME.SetFocus
        ValidationFailed = True
    ElseIf Len(Me.Caller_Type & vbNullString) = 0 Then
        MsgBox "Caller's Type Is Required"
        Me.Caller_Type.SetFocus
        ValidationFailed = True
    ElseIf IsNull(Me.Agency_Codes & vbNullString) = 0 Then
        MsgBox "Agency Code Is Required"
        Me.Agency_Codes.SetFocus
        ValidationFailed = True
    ElseIf IsNull(Me.Reason_Codes & vbNullString) = 0 Then
        MsgBox "Reason Code Is Required"
        Me.Reason_Codes.SetFocus
        ValidationFailed = True
    ElseIf IsNull(Me.[ACCOUNT_] & vbNullString) = 0 Then
        MsgBox "Account # Is Required"
        Me.ACCOUNT_.SetFocus
        ValidationFailed = True
    ElseIf IsNull(Me.FOLLOW_UP & vbNullString) = 0 Then
        MsgBox "Please enter Y or N for Follow Up"
        Me.FOLLOW_UP.SetFocus
        ValidationFailed = True
    ElseIf IsNull(Me.NOTE1_subform & vbNullString) = 0 Then
        MsgBox "Note Needed"
        Me.NOTE1_subform.SetFocus
        ValidationFailed = True
    End If
End Function

And here's the save button code:
Code:
Private Sub Add_Record_Click()
On Error GoTo Err_Add_Record_Click

    If Me.cmdSave.Caption = "Save" Then
        If ValidationFailed = False Then
            DoCmd.RunCommand acCmdSaveRecord
            Me.Add_Record.Caption = "New Call"
        End If
    Else
        If ValidationFailed = False Then
            DoCmd.GoToRecord , , acNewRec
            Me.cmdSave.Caption = "Save"
        End If
    End If
 
Exit_Add_Record_Click:
    Exit Sub
 
Err_Add_Record_Click:
    MsgBox Err.Description
    Resume Exit_Add_Record_Click
 
End Sub
 
I don't understand what I'm doing wrong. I tried to incorporate the validation code into the code you gave me earlier but I continue to get error message "Espected End Sub"
Code:
Private Sub Add_Record_Click()
On Error GoTo Err_Add_Record_Click
 
   If Me.cmdSave.Caption = "Save" Then
        Me.Add_Record.Caption = "New Call"
        If ValidationIsFine Then
Public Function ValidationFailed() As Boolean
    ' Validate required fields
    If Len(Me.CS_Rep & vbNullString) = 0 Then
        MsgBox "CS Rep Is Required"
        Me.CS_Rep.SetFocus
        ValidationFailed = True
    ElseIf Len(Me.CALLERS_NAME & vbNullString) = 0 Then
        MsgBox "Callers Name Is Required"
        Me.CALLERS_NAME.SetFocus
        ValidationFailed = True
    ElseIf Len(Me.Caller_Type & vbNullString) = 0 Then
        MsgBox "Caller's Type Is Required"
        Me.Caller_Type.SetFocus
        ValidationFailed = True
    ElseIf IsNull(Me.Agency_Codes & vbNullString) = 0 Then
        MsgBox "Agency Code Is Required"
        Me.Agency_Codes.SetFocus
        ValidationFailed = True
    ElseIf IsNull(Me.Reason_Codes & vbNullString) = 0 Then
        MsgBox "Reason Code Is Required"
        Me.Reason_Codes.SetFocus
        ValidationFailed = True
    ElseIf IsNull(Me.[ACCOUNT_] & vbNullString) = 0 Then
        MsgBox "Account # Is Required"
        Me.ACCOUNT_.SetFocus
        ValidationFailed = True
    ElseIf IsNull(Me.FOLLOW_UP & vbNullString) = 0 Then
        MsgBox "Please enter Y or N for Follow Up"
        Me.FOLLOW_UP.SetFocus
        ValidationFailed = True
    ElseIf IsNull(Me.NOTE1_subform & vbNullString) = 0 Then
        MsgBox "Note Needed"
        Me.NOTE1_subform.SetFocus
        ValidationFailed = True
    End If
End Function
 
   Else
   Me.cmdSave.capton = "Save"
   If ValidationIsFine Then
   DoCmd.GotToRecord , , acNewRec
   End If
   End If
 
Exit_Add_Record_Click:
    Exit Function
 
Err_Add_Record_Click:
    MsgBox Err.Description
    Resume Exit_Add_Record_Click
 
   End If
End Sub
 
Those are two separate blocks of code now. If they were together I would have consolidated them or written a comment.
 
I know they are seperate I already added the code to the save button.
My concern is with the validation code you entered above. I'm not sure if I was suppose to integrate it with the code you gave me before that. I'm putting the validatinon code on the New Call button but isn't there something else I need to add so it can append?
 
I know they are seperate I already added the code to the save button.
My concern is with the validation code you entered above. I'm not sure if I was suppose to integrate it with the code you gave me before that.
I'm putting the validatinon code on the New Call button but isn't there something else I need to add so it can append?
Like I mentioned, they are separate blocks of code, not to be consolidated. Put the first block of code just before or just after the save button code. There's nothing else that needs to be added.
 
I'm sorry if I'm sounding super annoying. I understand it's hard to explain to someone else something that comes to you quite easily. I have been there before many times. I really appreciate you helping me. But I feel like we are having communication problems. It would make the process easier and efficient if I explain to you where I'm at.

I'm trying to integrate this into One button and I'm under the impression this is going to do what I want.

You gave me two SEPERATE blocks of code. One was a validation code and the other I was supposed to add to the "Save Button". Correct me if I'm wrong? I thought we were getting rid of the save button.

And here's the save button code:
Code:

Code:
Private Sub Add_Record_Click()
On Error GoTo Err_Add_Record_Click
 
    If Me.cmdSave.Caption = "Save" Then
        If ValidationFailed = False Then
            DoCmd.RunCommand acCmdSaveRecord
            Me.Add_Record.Caption = "New Call"
        End If
    Else
        If ValidationFailed = False Then
            DoCmd.GoToRecord , , acNewRec
            Me.cmdSave.Caption = "Save"
        End If
    End If
 
Exit_Add_Record_Click:
    Exit Sub
 
Err_Add_Record_Click:
    MsgBox Err.Description
    Resume Exit_Add_Record_Click
 
End Sub

Just to make things clearer. Where am I supposed to add the validation code?

Code:
Public Function ValidationFailed() As Boolean
    ' Validate required fields
    If Len(Me.CS_Rep & vbNullString) = 0 Then
        MsgBox "CS Rep Is Required"
        Me.CS_Rep.SetFocus
        ValidationFailed = True
    ElseIf Len(Me.CALLERS_NAME & vbNullString) = 0 Then
        MsgBox "Callers Name Is Required"
        Me.CALLERS_NAME.SetFocus
        ValidationFailed = True
    ElseIf Len(Me.Caller_Type & vbNullString) = 0 Then
        MsgBox "Caller's Type Is Required"
        Me.Caller_Type.SetFocus
        ValidationFailed = True
    ElseIf IsNull(Me.Agency_Codes & vbNullString) = 0 Then
        MsgBox "Agency Code Is Required"
        Me.Agency_Codes.SetFocus
        ValidationFailed = True
    ElseIf IsNull(Me.Reason_Codes & vbNullString) = 0 Then
        MsgBox "Reason Code Is Required"
        Me.Reason_Codes.SetFocus
        ValidationFailed = True
    ElseIf IsNull(Me.[ACCOUNT_] & vbNullString) = 0 Then
        MsgBox "Account # Is Required"
        Me.ACCOUNT_.SetFocus
        ValidationFailed = True
    ElseIf IsNull(Me.FOLLOW_UP & vbNullString) = 0 Then
        MsgBox "Please enter Y or N for Follow Up"
        Me.FOLLOW_UP.SetFocus
        ValidationFailed = True
    ElseIf IsNull(Me.NOTE1_subform & vbNullString) = 0 Then
        MsgBox "Note Needed"
        Me.NOTE1_subform.SetFocus
        ValidationFailed = True
    End If
End Function

thanks
 
You only need ONE BUTTON with the initial caption as New Call. The code I gave you will perform both a Save and New Call function. It changes the caption automatically.
 
OH ok now we are on the same page.:cool: I did what you said to do. but now I'm getting two errors

1. for this part of the code I'm geting this error >> Compile Error: Type mismatch

Code:
ElseIf IsNull(Me.NOTE1_subform & vbNullString) = 0 Then
        MsgBox "Note Needed"
        Me.NOTE1_subform.SetFocus
        ValidationFailed = True

2. I test out the form and for the Agency Code it continues to tell me "Agency Code Is Required".
 
OH ok now we are on the same page.:cool:
It wasn't a communication problem afterall ;) You just didn't understand what the code was doing.

I did what you said to do. but now I'm getting two errors

1. for this part of the code I'm geting this error >> Compile Error: Type mismatch

Code:
ElseIf [COLOR=Red]IsNull[/COLOR](Me.NOTE1_subform & vbNullString) = 0 Then
        MsgBox "Note Needed"
        Me.NOTE1_subform.SetFocus
        ValidationFailed = True
Replace IsNull with Len

2. I test out the form and for the Agency Code it continues to tell me "Agency Code Is Required".
If you tested with the broken code then everything else will fail.
 
What do you mean broken code? please elaborate

I added the the code under Private Sub Add_Record_Click() in the New Call button and the I added the validation code two lines under End Sub like you said.
 
Broken code as per the your post #33, error 1.

Just replace the bit mentioned, Compile your code (i.e. in the code window, Debug menu > Compile) and test run it.
 
I noticed everything after Caller Type is giving me the #2 error i mentioned. I don't know how to edit the #1 error. I've edited all I could and it still gives me that error. Maybe I can't do it from a subform.
 
There are lots of cases where IsNull wasn't changed. So just replace all the IsNull with the word Len

 
DO YOU THINk it might have to do with the On Dirty code you gave me earlier?
 
If it was I would have said so. Have you amended the code yet?
 

Users who are viewing this thread

Back
Top Bottom