Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 339
  • Last Modified:

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
0
clive1
Asked:
clive1
1 Solution
 
priya_pbkCommented:
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
0
 
harsh008_kCommented:
clive,
u want date and time or just time?
0
 
priya_pbkCommented:
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

0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
priya_pbkCommented:
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
0
 
priya_pbkCommented:
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
0
 
nermeenCommented:
Hi
first of all set
Min and Max Date of Date Picker to defaults outside entry values
dtpControl.mindate = 0:dtpControl.MaxDate = "31/12/2099"

0
 
clive1Author Commented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now