inkserious
Technical User
- Jul 26, 2006
- 67
I have a UserForm which enters data into a structured table. I need to prevent duplicate records from being entered based on three criteria: date, shift and time.
Ideally, the user would be prompted with a Msgbox alerting them that there is a duplicate record. They would have the option to click Yes and overwrite the duplicate record, or no and return to the UserForm.
Below is the code I am currently using. Thanks in advance for any help anyone can provide.
Ideally, the user would be prompted with a Msgbox alerting them that there is a duplicate record. They would have the option to click Yes and overwrite the duplicate record, or no and return to the UserForm.
Below is the code I am currently using. Thanks in advance for any help anyone can provide.
Code:
Private Sub cmdSubmit_Click()
Dim ws As Worksheet
Dim lrowCount As Long
Dim ctl As Control
Set ws = Worksheets("Sheet4")
lrowCount = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
ws.Cells(lrowCount, 1).Value = Me.cboDate.Value
ws.Cells(lrowCount, 2).Value = Me.cboShift.Value
ws.Cells(lrowCount, 3).Value = Me.cboTime.Value
ws.Cells(lrowCount, 4).Value = Format(Me.txtDrop.Value, "#,##0")
ws.Cells(lrowCount, 5).Value = Format(Me.txtWin.Value, "#,##0")
ws.Cells(lrowCount, 6).Value = Format(Now(), "mm/dd/yy hh:mm")
For Each ctl In Me.Controls
If TypeName(ctl) = "TextBox" Or TypeName(ctl) = "ComboBox" Then
ctl.Value = ""
End If
Next ctl
End Sub