Link to home
Start Free TrialLog in
Avatar of clive1
clive1

asked on

Date time picker value from text field

Hi. I am developing a time sheet application for work and i am using the dtp control to enter start time, and finish times into TextBoxes. There is a command button beside each text field which, when clicked, displays a small form with a dtp control. When the user sets and accepts a time, e.g. 04:00 PM , this value is displayed in the appropriate TextBox on the first form and the second form is unloaded.

In the event that a user reloads the dtp form to edit their time, I would like the value in the date time picker to display the value displayed in the TextBox on the first form.

I keep getting an out of Min and Max Date range error when the second form is loaded.

I would like some example code that shows me how to set a date time picker from a TextBox string.
form2.dtpControl.Value = CDate(form1.txtFinTime.Text)   just doesn't work for me.
Thanks in advance
Clive
Avatar of priya_pbk
priya_pbk

I tried it works for me. This is what is did,

-Form1:
consists of a textBox, and a command button
code:
Private Sub Command1_Click()
Form2.Show
End Sub


--------------------------------------

In Form2:
Private Sub Form_Activate()
'MsgBox Form1.Text1
'MsgBox DTPicker1.Value
DTPicker1.Value = Form1.Text1
End Sub

---------------------------------------

I wrote this date in the text1 at runtime. ie 7/25/2002
Shows me the proper date in the Dtpicker1 what i had written in the textbox

Startup form is Form1.

Is this what you wanted.Hope this helps!

-priya
clive,
u want date and time or just time?
ok, try this. I think this is what you want.

Changes to my last code:
---------------------------------------------
-Form1:
consists of a textBox and a command button
copy this code in code window of form1

Private Sub Command1_Click()
Form2.Show
End Sub


---------------------------------------------
-Form2:
consists of a dtpicker and a command button
copy this code then
Private Sub Command1_Click()
Form1.Text1 = Format(DTPicker1.Value, "hh:mm")
Unload Me
End Sub

---------------------------------------------

Form1 is the startup form.

hope this helps!

-priya

Also add this code in form2

-Form2:
Private Sub Form_Load()
DTPicker1.Value = Form1.Text1
End Sub

This will put the value of the text box back to the dtpicker1

-priya
check if the text1 in form1 is nullstring or not, helps to handle errors, like this

-Form2:
Private Sub Form_Load()
If Not Form1.Text1 = "" Then DTPicker1.Value = Form1.Text1
End Sub

as harsh008_k asked, do you want date or time. What is the format of your dtpicker control. I think one can have a date or time and not both.

-priya
ASKER CERTIFIED SOLUTION
Avatar of nermeen
nermeen

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of clive1

ASKER

Thank you newmeen. I had a feeling that's what had to be done, but was unsure how to reset the min / max range, or to what limits to set them. It seems so easy when you have the answer.
Many thanks,
Clive