IM doing a simple data entry form for an excel sheet. I have 3 text boxes. txtID, txtRefDate and txtSeenDate and Im using the following code to add data in a new row
What I want to do is add another data item which checks dates in both txtRefDte and txtSeen to see if they are the same, if true it returns a 1 and if false returns a 0 into a new column (iRow4)
What in access VBA is pretty simple, it would seem is not so simple in excel VBA
any help would be greatly appreciated
Code:
Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("RefData")
'find first empty row in database
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
'check for a CHI number
If Trim(Me.txtCHI.Value) = "" Then
Me.txtCHI.SetFocus
MsgBox "Please enter a CHI number"
Exit Sub
End If
'copy the data to the database
'use protect and unprotect lines,
' with your password
' if worksheet is protected
With ws
' .Unprotect Password:="password"
ws.Cells(iRow, 1).Value = Me.txtCHI.Value
ws.Cells(iRow, 2).Value = Me.txtRefDte.Value
ws.Cells(iRow, 3).Value = Me.txtSeen.Value
' ws.Protect Password:="password"
End With
'clear the data
Me.txtCHI.Value = ""
Me.txtRefDte.Value = ""
Me.txtSeen.Value = ""
Me.txtCHI.SetFocus
End Sub
What I want to do is add another data item which checks dates in both txtRefDte and txtSeen to see if they are the same, if true it returns a 1 and if false returns a 0 into a new column (iRow4)
What in access VBA is pretty simple, it would seem is not so simple in excel VBA
any help would be greatly appreciated