Can someone please help with a persistant problem I have with using dates in VBA User Forms.
Requirement 1
To be able to input a date and other details into a user form which are then added into a worksheet
Requirement 2
To be able to search and recall these details back into the user form using the date detail.
Requirement 3
To be able to update recalled details and pass these updated details back to the worksheet using the date detail.
There are a number of other functions I will be looking to introduce but before I can consider these, I need to be able to add, search and update details using the date as the key.
I have tried various options to generate dates including using Date Picker and Text Boxes and have most recently tried searching by also using a Date Picker but the search is unable to find a match.
This is the test code to see a match could be found when a date added to the worksheet using a Date Picker could be found by searching using the same Date Picker. Unfortunately the Message Box is always the result.
NOTE: The Range "A:A" has been used as the range in column A will constantly be increasing
Please can someone provide me with a solution which will enable me to achieve the three above requirements.
What would be useful would be to understand are
1) Which control is best to be used (Text Box or DTPicker)
2) Which format should be applied to the "Date" column in the worksheet
3) The appropriate code to apply to a text box to
a) Instruct a user to key a set format if a Text Box is to be used (eg dd/mm/yyyy which appears to be the format applied by the DTPicker)
b) To ensure the keyed input information is passed in a date format
c) To ensure the keyed search information is passed in the same date format
4) If it is possible to re-populate a DTPicker control with the date following a search
Many thanks
Requirement 1
To be able to input a date and other details into a user form which are then added into a worksheet
Requirement 2
To be able to search and recall these details back into the user form using the date detail.
Requirement 3
To be able to update recalled details and pass these updated details back to the worksheet using the date detail.
There are a number of other functions I will be looking to introduce but before I can consider these, I need to be able to add, search and update details using the date as the key.
I have tried various options to generate dates including using Date Picker and Text Boxes and have most recently tried searching by also using a Date Picker but the search is unable to find a match.
VBA Code:
Private Sub cmdDateSearch_Click()
'Used to search for records for a specific date
Dim Res As Variant
Dim lastrow
Dim myFind As String
Res = Application.Match(txtDateSearch, Sheets ("Daily Hours Input").Range ("A:A"), 0)
If IsError(Res) Then
MsgBox "Date Not Found", vbInformation, "Date Not Found"
Call Userform_Initialize
txtDateSearch.SetFocus
Exit Sub
End If
End Sub
This is the test code to see a match could be found when a date added to the worksheet using a Date Picker could be found by searching using the same Date Picker. Unfortunately the Message Box is always the result.
NOTE: The Range "A:A" has been used as the range in column A will constantly be increasing
Please can someone provide me with a solution which will enable me to achieve the three above requirements.
What would be useful would be to understand are
1) Which control is best to be used (Text Box or DTPicker)
2) Which format should be applied to the "Date" column in the worksheet
3) The appropriate code to apply to a text box to
a) Instruct a user to key a set format if a Text Box is to be used (eg dd/mm/yyyy which appears to be the format applied by the DTPicker)
b) To ensure the keyed input information is passed in a date format
c) To ensure the keyed search information is passed in the same date format
4) If it is possible to re-populate a DTPicker control with the date following a search
Many thanks