Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DTPicker issue 2

Status
Not open for further replies.

Eugen Fintina

Programmer
Apr 27, 2005
29
RO
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.
 
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
 
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
 
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
 
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
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top