alyceinwonderland
New Member
- Joined
- Mar 14, 2021
- Messages
- 10
- Office Version
- 2007
- Platform
- Windows
Hi, Good day. I have this VBA project where in I have to compare the dates in my userform. Please help. Kindly see my script below for your reference. Thank you in advance.
I need the txtBS.Text to be less than or equal the date of the txtdate.Text.
I tried inserting this code to my VBA below but did not work:
If txtBS.Text <= txtdate.Text Then
MsgBox "The date entered into the before date is greater than the application."
Private Sub CommandButton4_Click()
On Error GoTo xlERR
If Trim(txtDN.Text) = "" Then GoTo xlERR
If Trim(txtCN.Text) = "" Then GoTo xlERR
If Trim(txtdate.Text) = "" Then
GoTo xlERR
ElseIf IsDate(txtdate.Text) = False Then
MsgBox "Invalid Date", vbCritical, "Input Data"
Exit Sub
End If
If Trim(txtAO.Text) = "" Then GoTo xlERR
If Trim(txtBS.Text) = "" Then
GoTo xlERR
ElseIf IsDate(txtBS.Text) = False Then
MsgBox "Invalid Date", vbCritical, "Input Data"
Exit Sub
End If
bLoading = True
Sheet2.Unprotect "CA"
Sheet2.Range("$M$9").Value = txtCN.Text
Sheet2.Range("$Z$3").Value = txtdate.Text
Sheet2.Range("$Z$4").Value = txtAO.Text
Sheet2.Range("$M$16").Value = txtBS.Text
bLoading = False
Sheet2.Protect "CA"
With ActiveWorkbook
For i = 1 To Sheets.Count
If (.Sheets(i).Name <> "MAIN") Then
.Sheets(i).Visible = True
End If
Next
If .Sheets("MAIN").Visible = True Then .Sheets("MAIN").Visible = False
If .Sheets("Data Validation").Visible = True Then .Sheets("Data Validation").Visible = False
Me.Hide
GoTo ProceedSave
.Sheets("CA").Activate
.Protect Password:="appleone"
End With
Exit Sub
I need the txtBS.Text to be less than or equal the date of the txtdate.Text.
I tried inserting this code to my VBA below but did not work:
If txtBS.Text <= txtdate.Text Then
MsgBox "The date entered into the before date is greater than the application."
VBA Code:
Private Sub CommandButton4_Click()
On Error GoTo xlERR
If Trim(txtDN.Text) = "" Then GoTo xlERR
If Trim(txtCN.Text) = "" Then GoTo xlERR
If Trim(txtdate.Text) = "" Then
GoTo xlERR
ElseIf IsDate(txtdate.Text) = False Then
MsgBox "Invalid Date", vbCritical, "Input Data"
Exit Sub
End If
If Trim(txtAO.Text) = "" Then GoTo xlERR
If Trim(txtBS.Text) = "" Then
GoTo xlERR
ElseIf IsDate(txtBS.Text) = False Then
MsgBox "Invalid Date", vbCritical, "Input Data"
Exit Sub
End If
bLoading = True
Sheet2.Unprotect "CA"
Sheet2.Range("$M$9").Value = txtCN.Text
Sheet2.Range("$Z$3").Value = txtdate.Text
Sheet2.Range("$Z$4").Value = txtAO.Text
Sheet2.Range("$M$16").Value = txtBS.Text
bLoading = False
Sheet2.Protect "CA"
With ActiveWorkbook
For i = 1 To Sheets.Count
If (.Sheets(i).Name <> "MAIN") Then
.Sheets(i).Visible = True
End If
Next
If .Sheets("MAIN").Visible = True Then .Sheets("MAIN").Visible = False
If .Sheets("Data Validation").Visible = True Then .Sheets("Data Validation").Visible = False
Me.Hide
GoTo ProceedSave
.Sheets("CA").Activate
.Protect Password:="appleone"
End With
Exit Sub