I am creating a userform that is pretty simple.
The form posts the current date, Name of an employee, start date and an end date for leave.
So it has
1 txtbox for the current date
2 ComboBox for employee drop down list of names
3 txtbox for start date
4. txtbox for end date
I would like without have to create another command button have the two date txtboxes subtract from each other and return the # of days taken to post in a flat database with the other information.
Here is my current code and it is work really good as it is now but it just posts current date, name, and the two days. I would like it to post the # of days too.
I found this code searching the web " TextBox3.Value = CDbl(TextBox1.Value) - CDbl(TextBox2.Value)". I have no idea where it shouuld go? I am super new to VBA,,,this is my first code.
The form posts the current date, Name of an employee, start date and an end date for leave.
So it has
1 txtbox for the current date
2 ComboBox for employee drop down list of names
3 txtbox for start date
4. txtbox for end date
I would like without have to create another command button have the two date txtboxes subtract from each other and return the # of days taken to post in a flat database with the other information.
Here is my current code and it is work really good as it is now but it just posts current date, name, and the two days. I would like it to post the # of days too.
I found this code searching the web " TextBox3.Value = CDbl(TextBox1.Value) - CDbl(TextBox2.Value)". I have no idea where it shouuld go? I am super new to VBA,,,this is my first code.
Code:
Private Sub cmdAddData_Click()
Dim ws As Worksheet
Dim Addto As Range
Set ws = Sheet2
Set Addto = ws.Range("c65356").End(xlUp).Offset(1, 0)
With ws
Addto = txtDate.Value
Addto.Offset(0, 1).Value = cboName.Value
Addto.Offset(0, 2).Value = txtStart.Value
Addto.Offset(0, 3).Value = txtEnd.Value
End With
txtDate.Value = Format(Date, "Medium Date")
cboName.Value = ""
txtStart.Value = ""
txtEnd.Value = ""
End Sub
Private Sub cmdClose_Click()
Unload Me
End Sub
Private Sub cmdView_Click()
Unload Me
Sheet2.Select
Sheet2.Range("A1").Select
End Sub
Private Sub UserForm_Click()
End Sub
Private Sub UserForm_Initialize()
txtDate.Value = Format(Date, "Medium Date")
Me.cboName.SetFocus
End Sub
Last edited by a moderator: