Hi experts,gud day!

Here I am again needing your help. How will I code condition that textbox will only be enable after 6 months from date of hired or textbox will be disabled after typing certain amounts because it is not yet 6 months from date of hired. A message box will pop up before 6 months, "You are not allowed to make Cash Advances for now".

I really dont have idea on how will I condition the date of hired after 6 months to present date.

Below is where you will insert the condition. Please!

____
Private Sub cmdSearch_Click()

Set rs = New ADODB.Recordset
rs.Open "Select Lastname, Firstname, Middle_Initial, Rate, Date_Hired from Employees where Employees_IdNo Like '" & txtSearch & "'", cn, adOpenKeyset, adLockPessimistic
If Not rs.EOF Then

Ado.RecordSource = "Select Lastname, Firstname, Middle_Initial, Rate, Date_Hired from Employees where Employees_IdNo Like '" & txtSearch & "'"
Ado.Refresh

lblAllowable.Caption = Round(Val(lblRate * 30 * 0.4), 2)
lblAllowable.Caption = Format(lblAllowable.Caption, "#,##0.00")

rs.Close
Set rs = Nothing

Else
MsgBox "No entry yet for this ID Number", vbCritical, "Charges"
End If
End Sub
_____

Thanks a lot,

Kimangel

Recommended Answers

All 3 Replies

Try the following...

Private Sub cmdSearch_Click()
Set rs = New ADODB.Recordset
rs.Open "Select Lastname, Firstname, Middle_Initial, Rate, Date_Hired from Employees where Employees_IdNo Like '" & txtSearch & "'", cn, adOpenKeyset, adLockPessimistic
If Not rs.EOF Then
Ado.RecordSource = "Select Lastname, Firstname, Middle_Initial, Rate, Date_Hired from Employees where Employees_IdNo Like '" & txtSearch & "'"
Ado.Refresh

Dim xHired As Date, xLaterDate As Date, xNow As Date

'Get saved hired date...
xHired = rs!Date_Hired
'Add 6 months days to value, work on average of 30 days per month. This can be made specific, quite a lot of code involved though...
xLaterDate = xHired + 180
xNow = Now

If xNow > xLaterDate Then
    lblAllowable.Enabled = False
    lblAllowable.Caption = "Still under hiring contract"
        Else
    lblAllowable.Caption = Round(Val(lblRate * 30 * 0.4), 2)
    lblAllowable.Caption = Format(lblAllowable.Caption, "#,##0.00")
    rs.Close
    Set rs = Nothing
End If
Else
MsgBox "No entry yet for this ID Number", vbCritical, "Charges"
End If
End Sub

thanks a lot sir, the condition is now ok. I just change the greater than symbol to less than.

Regards

kimangel

Oops, my bad. :) Only a pleasure. Happy coding.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.