Data Validation from Delete Command Button

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
 
B

Brendan Reynolds

Your code has several references to an object named 'Cancel', e.g. ...

Cancel.acCmdDeleteRecord

There is no such object built-in to Access or VBA. Unless this is a custom
class that you have created (in which case you need to instantiate it before
using it), you should probably take out those lines and change the code to
something like this ...

If IsNull(Me.DeleteDate) Then
MsgBox conMESSAGE, vbExclamation, "DELETION DATE MUST BE COMPLETED
BEFORE CONTINUING"
Me.DeleteDate.SetFocus
Exit Sub
Else

--
Brendan Reynolds
Access MVP

Sue Wilkes said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Delete Button 2
Access Message 1
Data Validation & Cancel Exit Command 5
Modifying Delete Button code 12
Back to Basics 1
VBA works in orignal but fails in copy of database 1
Validation Code Error 0
Before Update 6

Top