Help!!!! I have searched and searched. I am building a form for work for our different departments. When testing it. I hit the add button. A message box pops up Please add Fiscal Year! But the record is still added to the table with the Fiscal year missing. The only way the form recognizes the Fiscal year is missing is if I put the code under CmdAdd_Click(). I have read about putting the code in before update and such. Maybe I need to remove all of the if thens out of CmdAdd and then test placing the if then codes somewhere else. I really need help, no one else around here is very familiar to Access I am so close to finishing this form if I could just get this part to work.
Private Sub CmdAdd_Click()
'Add data to form
CurrentDb.Execute "INSERT INTO Scorecards (ForTheMonth,FiscalYear,Groups,Contact,Goals,Bench marks,Results,Comments)" & _
"VALUES('" & Me.ComboMonth & "','" & Me.ComboFiscal & "','" & Me.ComboDepartment & "','" & Me.txtContact & "','" & Me.ComboGoals & "','" & Me.txtBenchmarks & "','" & Me.TxtActualBenchmark & "','" & Me.txtComments & "');"
'message box
If IsNull(Me.ComboFiscal) Then ' No business unit
MsgBox ("Please add Fiscal Year!"), vbOKCancel ' Tell user
Me.ComboFiscal.SetFocus ' Focus the control
Exit Sub ' Exit the method
End If ' End the IsNull test
If IsNull(Me.txtContact) Then ' No business unit
MsgBox ("Please add Contact!"), vbOKCancel ' Tell user
Me.txtContact.SetFocus ' Focus the control
Exit Sub ' Exit the method
End If ' End the IsNull test
If IsNull(Me.TxtActualBenchmark) Then ' No business unit
MsgBox ("Please add Results!"), vbOKCancel
Me.TxtActualBenchmark.Undo ' Undo
Me.TxtActualBenchmark.SetFocus ' Focus the control
Exit Sub ' Exit the method
End If ' End the IsNull test
If IsNull(Me.ComboGoals) Then ' No business unit
MsgBox ("Please add Goals!"), vbOKCancel ' Tell user
Me.ComboGoals.SetFocus ' Focus the control
Exit Sub ' Exit the method
End If ' End the IsNull test
If Me.ComboMonth = "January" And TxtActualBenchmark.Value = "N/A" Then
MsgBox "Sorry but value cannot be N/A for the selected month"
Cancel = True
End If
If Me.ComboMonth = "February" And TxtActualBenchmark.Value = "N/A" Then
MsgBox "Sorry but value cannot be N/A for the selected month"
Cancel = True
End If
If Me.ComboMonth = "April" And TxtActualBenchmark.Value = "N/A" Then
MsgBox "Sorry but value cannot be N/A for the selected month"
Cancel = True
End If
If Me.ComboMonth = "May" And TxtActualBenchmark.Value = "N/A" Then
MsgBox "Sorry but value cannot be N/A for the selected month"
Cancel = True
End If
If Me.ComboMonth = "July" And TxtActualBenchmark.Value = "N/A" Then
MsgBox "Sorry but value cannot be N/A for the selected month"
Cancel = True
End If
If Me.ComboMonth = "August" And TxtActualBenchmark.Value = "N/A" Then
MsgBox "Sorry but value cannot be N/A for the selected month"
Cancel = True
End If
If Me.ComboMonth = "October" And TxtActualBenchmark.Value = "N/A" Then
MsgBox "Sorry but value cannot be N/A for the selected month"
Cancel = True
End If
If Me.ComboMonth = "November" And TxtActualBenchmark.Value = "N/A" Then
MsgBox "Sorry but value cannot be N/A for the selected month"
Cancel = True
End If
If IsNumeric(Me.TxtActualBenchmark) = "False" _
And txtBenchmarks.Value = "No negatives" Then
Cancel = True
Me.TxtActualBenchmark.Undo
MsgBox "Please enter a numeric value ", _
vbInformation, "Missing Information"
End If
'Requery Form
frmscorecardssub.Form.Requery
'Clear Form
CmdClear_Click
End Sub
Private Sub CmdClear_Click()
Me.ComboGoals = ""
Me.txtBenchmarks = ""
Me.txtContact = ""
Me.ComboDepartment = ""
Me.TxtActualBenchmark = ""
Me.txtComments = ""
Me.ComboGoals.SetFocus
End Sub
Private Sub CmdClose_Click()
DoCmd.Close
End Sub
Private Sub ComboDepartment_AfterUpdate()
Me.ComboGoals.Requery
Me.frmscorecardssub.Form.Requery
End Sub
Private Sub ComboDepartment_Change()
Me.txtContact.Value = Me.ComboDepartment.Column(1)
End Sub
Private Sub ComboFiscal_BeforeUpdate(Cancel As Integer)
End Sub
Private Sub ComboGoals_Change()
Me.txtBenchmarks.Value = Me.ComboGoals.Column(1)
End Sub
Private Sub Form_BeforeUpdate(Cancel As Integer)
End Sub
Private Sub Form_Dirty(Cancel As Integer)
If IsNull(Me.ComboMonth) And IsNull(Me.ComboFiscal) And IsNull(Me.txtContact) And IsNull(Me.ComboGoals) And IsNull(Me.txtBenchmarks) And IsNull(Me.TxtActualBenchmark) Then
Me.CmdAdd.Enabled = False
Else
Me.CmdAdd.Enabled = True
End If
End Sub
Private Sub Form_Load()
'Clear Form
CmdClear_Click
End Sub
Private Sub TxtActualBenchmark_BeforeUpdate(Cancel As Integer)
If IsNull(Me.TxtActualBenchmark) Then ' No business unit
MsgBox "Please add Results!"
Me.TxtActualBenchmark.Undo ' Undo
Me.TxtActualBenchmark.SetFocus ' Focus the control
Exit Sub ' Exit the method
End If ' End the IsNull test
If IsNumeric(Me.TxtActualBenchmark) = "False" _
And txtBenchmarks.Value = "No negatives" Then
Cancel = True
Me.TxtActualBenchmark.Undo
MsgBox "Please enter a numeric value ", _
vbInformation, "Missing Information"
End If
End Sub