Date in userform textbox is deleted when date is selected in other textbox from Calender.

sathyaganapathi

Board Regular
Joined
Apr 29, 2021
Messages
81
Office Version
  1. 2016
Platform
  1. Windows
Hi all,
I have peculier issue in excel userform.
There are two text boxes in a user form to capture the dates.
One is the sample input date and other one is for entering the date of a particular activity.
The date in first text box is inserted using below code.

VBA Code:
Private Sub FIInputDatePick_click()
    Me.txtDate.SetFocus
    Me.txtDate.Value = VBA.Format(Now(), "mm/dd/yyyy HH:mm")
End Sub

and the date in second textbox with below code. I use a Selected_datetime function to select a date from a calender.

VBA Code:
Private Sub FileCheck1Datepick_Click()
Call Date_Time_Picker.Selected_DateTime(frm_PlabFinalLog.FileCheck1Date)
    frm_PlabFinalLog.FileCheck1Date.Value = VBA.Format(frm_PlabFinalLog.FileCheck1Date.Value, "mm/dd/yyyy hh:mm")
End Sub

The problem is, when the second code us run, the date in the 1st textbox is getting deleted automatically. There is no connection or link between two codes. But, both are in same userform.
Could anybody please help on this? Please let me know if more info is need to find the problem...
Thanks.
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
What if you saved the TextBox value and restored it later?

VBA Code:
Private Sub FileCheck1Datepick_Click()
Dim SaveDate As String
    
    SaveDate = Me.txtDate.Value
    Call Date_Time_Picker.Selected_DateTime(frm_PlabFinalLog.FileCheck1Date)
    frm_PlabFinalLog.FileCheck1Date.Value = VBA.Format(frm_PlabFinalLog.FileCheck1Date.Value, "mm/dd/yyyy hh:mm")
    Me.txtDate.Value = SaveDate
End Sub
 
Upvote 0
What if you saved the TextBox value and restored it later?

VBA Code:
Private Sub FileCheck1Datepick_Click()
Dim SaveDate As String
   
    SaveDate = Me.txtDate.Value
    Call Date_Time_Picker.Selected_DateTime(frm_PlabFinalLog.FileCheck1Date)
    frm_PlabFinalLog.FileCheck1Date.Value = VBA.Format(frm_PlabFinalLog.FileCheck1Date.Value, "mm/dd/yyyy hh:mm")
    Me.txtDate.Value = SaveDate
End Sub
Dear rlv01,
Thanks for the input. I tried with the above code and still the date is getting deleted.

I tried by modifying your code as below and checked again. But, result is, again the date is getting deleted.

VBA Code:
Private Sub FIInputDatePick_click()
Dim SaveDate As String
    Me.txtDate.SetFocus
    Me.txtDate.Value = VBA.Format(Now(), "mm/dd/yyyy HH:mm")
    SaveDate = Me.txtDate.Value
End Sub

Private Sub FileCheck1Datepick_Click()
Dim SaveDate As String
    Call Date_Time_Picker.Selected_DateTime(frm_PlabFinalLog.FileCheck1Date)
    frm_PlabFinalLog.FileCheck1Date.Value = VBA.Format(frm_PlabFinalLog.FileCheck1Date.Value, "mm/dd/yyyy hh:mm")
    Me.txtDate.Value = SaveDate
End Sub

any other possibilities please?
 
Upvote 0
Use the VBE editor to single-step through each statement your code until you find the statement that is deleting the date from the other TextBox
 
Upvote 0
Use the VBE editor to single-step through each statement your code until you find the statement that is deleting the date from the other TextBox
Hi rlv01,
Since I am using userform and not expert in VBA coding, I could not check with VBA Editor.. Could you please let me know how to check single-step chekc through VBA Editor when using userform?
Thanks.
 
Upvote 0
The VBA Editor (or more commonly known as VBE) is the tool used to create, modify and maintain Visual Basic for Applications (VBA) procedures and modules in Excel. You access it from Excel with Alt-F11. If you have been making changes to your UserForm code then you are already using VBE. To single step code, watch this tutorial.


The relevant portion starts at 1:21:39.
 
Upvote 0
The VBA Editor (or more commonly known as VBE) is the tool used to create, modify and maintain Visual Basic for Applications (VBA) procedures and modules in Excel. You access it from Excel with Alt-F11. If you have been making changes to your UserForm code then you are already using VBE. To single step code, watch this tutorial.


The relevant portion starts at 1:21:39.
Hi rlv01,
Thanks for the link and the guidance! I will go through it soon. As I was away from the station for few days, I could not see your post...!
Thanks again.
Best regards.
 
Upvote 0

Forum statistics

Threads
1,214,386
Messages
6,119,214
Members
448,874
Latest member
b1step2far

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top