If Me.NewRecord = True Then
If (Not IsNull(DLookup("[UniqueID]", "tblScheduleRecords", "[UniqueID] ='" & Me!txtUniqueID & "'"))) Then
MsgBox "This client has already been scheduled for this Group, Schedule Date & Time."
Cancel = True
End If
End If
But if the record already exists I want the record to be deleted from the datasheet. How can I accomplish this?
ASKER
Dim Records As DAO.Recordset
If Me.NewRecord = True Then
Set Records = Me.RecordsetClone
Records.FindFirst "[UniqueID] = '" & Me!txtUniqueID.Value & "'"
If Not Records.NoMatch Then
Records.Delete
End If
Records.Close
End If
ASKER
Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo Err_Form_BeforeUpdate
If Me.NewRecord = True Then
If (Not IsNull(DLookup("[UniqueID]", "tblScheduleRecords", "[UniqueID] ='" & Me!txtUniqueID & "'"))) Then
MsgBox "This client has already been scheduled for this Group, Schedule Date & Time."
Cancel = True
End If
End If
Exit_Form_BeforeUpdate:
Exit Sub
Err_Form_BeforeUpdate:
MsgBox "Error Number: " & Err.Number & vbCrLf & "Error Description: " & Err.Description & vbCrLf & "Error Source: " & Err.Source
Resume Exit_Form_BeforeUpdate
End Sub
I just want the user to get the warning, and then clear the record entry in the subform.
Private Sub Form_BeforeInsert(Cancel As Integer)
Dim Records As DAO.Recordset
Set Records = Me.RecordsetClone
Records.FindFirst "[UniqueID] = '" & Me!txtUniqueID.Value & "'"
If Not Records.NoMatch Then
MsgBox "This client has already been scheduled for this Group, Schedule Date & Time."
Cancel = True
End If
Records.Close
End Sub
ASKER
Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.
TRUSTED BY