S
Sue Wilkes
I have a delete command button on my form which I want to perform data
validation on several fields before carrying out the action if all is
correct. I have the following coding and in the main it works. The error
message appears if the data is missing followed by the message 'object
required'. Is it possible someone could tell what I'm doing wrong I'm out of
ideas. Many thanks in anticipation from a grateful user of this discussion
group.
Private Sub RegDelRec_Click()
On Error GoTo Err_RegDelRec_Click
Dim strWhere As String
Dim stDocName As String
If IsNull(Me.DeleteDate) Then
MsgBox conMESSAGE, vbExclamation, "DELETION DATE MUST BE COMPLETED
BEFORE CONTINUING"
Cancel.acCmdDeleteRecord
Me.DeleteDate.SetFocus
Else
If IsNull(Me.PersonReqDel) Then
MsgBox conMESSAGE, vbExclamation, "PERSONS REQUIRING THE DELETION MUST
BE COMPLETED BEFORE CONTINUING"
Cancel.acCmdDeleteRecord
Me.PersonReqDel.SetFocus
Else
If IsNull(Me.DeptReqDel) Then
MsgBox conMESSAGE, vbExclamation, "DEPARTMENT REQUIRING THE DELETION
MUST BE COMPLETED BEFORE CONTINUING"
Cancel.acCmdDeleteRecord
Me.DeptReqDel.SetFocus
Else
If IsNull(Me.ReasonforDel) Then
MsgBox conMESSAGE, vbExclamation, "REASONS FOR DELETION MUST BE
COMPLETED BEFORE CONTINUING"
Cancel.acCmdDeleteRecord
Me.ReasonforDel.SetFocus
End If
End If
End If
End If
RunCommand acCmdDeleteRecord
If Me.Dirty Then 'Save any edits.
Me.Dirty = False
End If
If Me.NewRecord Then 'Check there is a record to print
MsgBox "Select a record to print"
Else
strWhere = "[RegisterNumber] = """ & Me.[RegisterNumber] & """"
stDocName = "DeletePrintM"
DoCmd.RunMacro stDocName
End If
'Undo Disable/Grey Out the "Add Record" and "Edit Record" Buttons
Me!AddNewRec.Enabled = True
Me!EditRec.Enabled = True
'Undo Disable/Grey Out the Text Boxes Not Applicable To Delete A Record
Me!RegisterNumber.Enabled = True
Me!DeptCode.Enabled = True
Me!DateSent.Enabled = True
Me!Designation.Enabled = True
Me!SentTo.Enabled = True
Me!CompanyNames.Enabled = True
Me!CopiedTo.Enabled = True
Me!Subject.Enabled = True
Me!Hyperlink1.Enabled = True
Me!Hyperlink2.Enabled = True
Me!Hyperlink3.Enabled = True
Me!ReasonsforEdit.Enabled = True
Exit_RegDelRec_Click:
Exit Sub
Err_RegDelRec_Click:
MsgBox Err.Description
Resume Exit_RegDelRec_Click
End Sub
validation on several fields before carrying out the action if all is
correct. I have the following coding and in the main it works. The error
message appears if the data is missing followed by the message 'object
required'. Is it possible someone could tell what I'm doing wrong I'm out of
ideas. Many thanks in anticipation from a grateful user of this discussion
group.
Private Sub RegDelRec_Click()
On Error GoTo Err_RegDelRec_Click
Dim strWhere As String
Dim stDocName As String
If IsNull(Me.DeleteDate) Then
MsgBox conMESSAGE, vbExclamation, "DELETION DATE MUST BE COMPLETED
BEFORE CONTINUING"
Cancel.acCmdDeleteRecord
Me.DeleteDate.SetFocus
Else
If IsNull(Me.PersonReqDel) Then
MsgBox conMESSAGE, vbExclamation, "PERSONS REQUIRING THE DELETION MUST
BE COMPLETED BEFORE CONTINUING"
Cancel.acCmdDeleteRecord
Me.PersonReqDel.SetFocus
Else
If IsNull(Me.DeptReqDel) Then
MsgBox conMESSAGE, vbExclamation, "DEPARTMENT REQUIRING THE DELETION
MUST BE COMPLETED BEFORE CONTINUING"
Cancel.acCmdDeleteRecord
Me.DeptReqDel.SetFocus
Else
If IsNull(Me.ReasonforDel) Then
MsgBox conMESSAGE, vbExclamation, "REASONS FOR DELETION MUST BE
COMPLETED BEFORE CONTINUING"
Cancel.acCmdDeleteRecord
Me.ReasonforDel.SetFocus
End If
End If
End If
End If
RunCommand acCmdDeleteRecord
If Me.Dirty Then 'Save any edits.
Me.Dirty = False
End If
If Me.NewRecord Then 'Check there is a record to print
MsgBox "Select a record to print"
Else
strWhere = "[RegisterNumber] = """ & Me.[RegisterNumber] & """"
stDocName = "DeletePrintM"
DoCmd.RunMacro stDocName
End If
'Undo Disable/Grey Out the "Add Record" and "Edit Record" Buttons
Me!AddNewRec.Enabled = True
Me!EditRec.Enabled = True
'Undo Disable/Grey Out the Text Boxes Not Applicable To Delete A Record
Me!RegisterNumber.Enabled = True
Me!DeptCode.Enabled = True
Me!DateSent.Enabled = True
Me!Designation.Enabled = True
Me!SentTo.Enabled = True
Me!CompanyNames.Enabled = True
Me!CopiedTo.Enabled = True
Me!Subject.Enabled = True
Me!Hyperlink1.Enabled = True
Me!Hyperlink2.Enabled = True
Me!Hyperlink3.Enabled = True
Me!ReasonsforEdit.Enabled = True
Exit_RegDelRec_Click:
Exit Sub
Err_RegDelRec_Click:
MsgBox Err.Description
Resume Exit_RegDelRec_Click
End Sub