INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

DTPicker issue

DTPicker issue

(OP)
1. I added, to a form, a DTPicker control (Tools -> Options -> Controls -> ActiveX Controls -> Microsoft Date and Time Picker Control 6.0).
2. I changed the control’s name from Olecontrol1 in DTPicker.
3. If I changed the ControlSource value from none to a table field's AND if I have no records into the table I’ve got an error (OLE lDispatch exception code 0 from DTPicker: Property is read-only.. Unbiding object dtpicker.) If populated the table to which DTPicker is bound I’ve got no error.
4. Also, if I emptied the date field's value from the table I’ve got another error.

It seems that DTPicker does not allow empty or none values for ControlSource’s values. It is correct or I've done something wrong?
Can you help me with a simple workaround for this issue? I can imagine something but it seems too complicated to implement.

RE: DTPicker issue

Quote:

It seems that DTPicker does not allow empty or none values for ControlSource’s values.

That is completely correct.

Empty dates are a VFP-specific concept. In general, they are not supported by ActiveX controls. The usual workaround is to test the underlying field for an empty date in the control's GotFocus. If it is empty, change it to NULL (which the control does support). For the same reason, you shouldn't use the control's ControlSource property. Instead, use the control's Value property to update the relevant field in the underlying table.

This is the reason that most VFP developers prefer not to use the DTPicker, but instead use a native VFP calendar control, of which there are many available. Or, write your own, which is really not that difficult.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: DTPicker issue

(OP)
Hello, Mike

Are there other issues that can rise in use of DTPicker ActiveX? I must use such component only once on single form. I think that’s easier to modify my work style to cover component’s requirement than to understand the way that other component work. At least at this moment.

Thank you again,
Eugen

RE: DTPicker issue

Eugen, I'm not aware of any other issues - other than the need to distribute the OCX file (CMCTL32.OCX) with your application.

By the way, I hope I didn't mislead you when I said to not use the ControlSource. You can use the ControlSource to display the existing date in the underlying field, but not to update it. And if the underlying field is an empty date, you can remove the ControlSource in the GotFocus and restore in the LostFocus.

Also, rather than using the Value property to update the table, it might be more reliable to use the Year, Month and Day properties. In other words:

CODE -->

WITH THIS
  REPLACE MyDateField WITH DATE(.Year, .Month, .Day)
ENDWITH 

I'm not quite sure why that is more reliable than using the Value, but, looking back at some of my old code, I see that that is what I have always done.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: DTPicker issue

(OP)
Mike, are you sure that CMCTL32.OCX include the DTPicker component? I can’t find it on my HDD. I thought that MSCOMCT2.OCX is the required for distribution. Am I wrong?

Your example and details are helpfully. Thanks’ for it!

All the best,
Eugen

RE: DTPicker issue

Aplogies. I think it should be COMCTL32.OCX (not CMCTL32.OCX)). I don't recognise MSCOMCT2.OCX, but you might be right about that. You might have to try it and see.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: DTPicker issue

In the blog post that Tamar recommended, I see that Doug changes an empty date to the current date, rather than to NULL as I suggested. In many situations, this makes a lot of sense. It means that the user will see something meaningful when navigating to a record containing an empty date.

But not in all cases. Sometimes you will want to convey the fact that no date has been entered, rather than defaulting to today's date. (For example, the field might be used for employees' dates of birth; if you don't know a given person's birth date, you definitely can't assume he was born today.) In those cases, it might be better to disable or hide the control. But if the field is editable, then you will also need a way for the user to re-enable or un-hide the control so that they can go ahead and enter the correct value.

Nothing of this is particularly difficult, but it does take a bit of thought.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close