DharmeshKP
New Member
- Joined
- Feb 15, 2020
- Messages
- 34
- Office Version
- 2007
- Platform
- Windows
I have userform for patient data entry. I wants to avoid duplicate entry with a condition that it should not be duplicate on current date. Patient may come after few days and needs to be reentered but it should not happen on same day means on curren date. I tried following code but it shows error. Please help me to debug it.
VBA Code:
Private Sub CommandButton2_Click()
Dim x As Long
Dim y As Worksheet
Dim c As Range
Set y = Sheets("Daily")
x = y.Range("A" & Rows.Count).End(xlUp).Row
lrow = y.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).Row
FindDate = Format(Date, "dd/mm/yyyy")
' find first row containing current date
[B]frow = y.Cells.Find(What:=FindDate, SearchDirection:=xlNext, SearchOrder:=xlByRows).Row
'error line in above[/B]
With y.Range(y.Cells(frow, 1), y.Cells(lrow, 1))
Set c = .Find(Me.TextBox1.Value, LookIn:=xlValues, LookAt:=xlWhole)
End With
If c Is Nothing Then
With y
.Cells(x + 1, "A").Value = TextBox1.Text
.Cells(x + 1, "B").Value = TextBox2.Text
.Cells(x + 1, "C").Value = TextBox3.Text
.Cells(x + 1, "D").Value = TextBox4.Text
.Cells(x + 1, "E").Value = TextBox5.Text
.Cells(x + 1, "F").Value = TextBox6.Text
.Cells(x + 1, "G").Value = TextBox7.Text
.Cells(x + 1, "H").Value = TextBox8.Text
.Cells(x + 1, "I").Value = [now()]
.Cells(x + 1, "J").Value = Application.UserName
End With
'clear the data
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""
TextBox8.Text = ""
ActiveWorkbook.Save
Else: MsgBox TextBox1.Value & " is already registered "
Exit Sub
End If
End Sub