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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS Date & Time Picker Control Usage 1

Status
Not open for further replies.

Alexschmidt

IS-IT--Management
Jan 26, 2003
33
ZA
I have a form with two fields on it, one being a date field for which I have added the MS Date and Time Picker Control V6.0. The 'Controlsource' points to the date field in the table. I have also dropped the VFP Data Navigation Button Class (Foundation Class) onto the form for the purpose of Add, Edit, Delete ...
The table is not updated to reflect a selected date from the picker when Adding or Editing. How would I get the button class to recognize and save changes to the table when using the picker? Thanks...
 
What do you have in the init and double click of the form?

My init is: (m.run_date is a variable from the form, substitute your dbf field for this)

with thisform
local ldDate
ldDate = iif(empty(m.run_date), date(), m.run_date)
.Olecontrol1.month = month(ldDate)
.Olecontrol1.day = day(ldDate)
.Olecontrol1.year = year(ldDate)
.Olecontrol1.refresh()

.Olecontrol1.DayFont.size=10
.Olecontrol1.GridFont.size=10
.Olecontrol1.TitleFont.size=12
.Olecontrol1.monthLength=2

endwith

The click event of the OK button is:
(again change the name of the m.run_date var)

with thisform
m.run_date = ctod(alltrim(str(.Olecontrol1.month)) + '/' + ;
alltrim(str(.Olecontrol1.day)) + '/' + ;
alltrim(str(.Olecontrol1.year)))
.release()
endwith

Sorry about the formatting, cannot seem to get it right.
 
Alex,

I think I once ran into a similar problem. If memory serves, my solution was to put this code in the control's LostFocus:

SELECT RelevantTable
REPLACE MyDateField WITH DATE(this.year, this.month, this.day)

Not 100 percent sure if the above is correct, but you could give it a try.

Also, be aware that the DTPicker will report an error if you navigate to a record that has a blank date.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
Mike
Do you have a solution for the error ocurring on a blank date field in a record?
My table will have to be initiated with a record containing a filled date field and nothing else, this to prevent the error on an empty table. One can obviously delete the blank record after entering the first valid record but this seems a clumsy way to start and I then run the risk of having a client delete all records in a table which will once again trigger the error on the next use of the table with the DTpicker. I have tried using the neoDTpicker which boasts the ability to accommodate empty date fields but the same error is triggered the moment you have a record with a blank date field in the table.
Regards
Alex
 
The best solution I know for the empty date problem with the date and time picker comes from Marcia Akins and is in her book MegaFox. Basically, you add a custom property to hold the controlsource and a couple of methods that swap data in and out.

If you get FoxPro Advisor, take a look at my article in the April issue for the details.

Tamar
 
I couldn't stand the datetimepicker from MS (though I am a huge fan of MS for the most part). It hasn't been upgraded in years, doesn't allow you to change the color of the text shown in it (not talking about the monthview control dropdown here) and as you point out it doesn't handle empty or null dates very well. So I wrote my own VFP classes to handle Date and Datetime picking (I still utilized the monthview control for the calendar dropdown, so it is still dependent on that Active-X). You can run a sample of it from the code in...

Better Date\Datetime Controls faq184-3913

boyd.gif

 
Alex,

Do you have a solution for the error ocurring on a blank date field in a record?

The way I do it is to check for a blank date when navigating to a record (which includes opening a table or requerying a view). If it is blank, I remove the ControlSource. If the user edits the date within the dtPicker, I programmatically REPLACE this into the underlying field in the LostFocus, and then restore the ControlSource.

It's not a particularly nice approach, and I'm sure there are better ways to do it. I suggest you take a look at Marcia's solution as well.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
After receiving word that the FAQ I posted a link to above had multiple errors, I went and looked at it. Tek-Tips mangled the FAQ again by turning all the double-quotes into """, I've fixed this on my FAQs a few times in the past and yet it still ended up messed up again. My apologies to any members who might have tried it and gotten errors. I've fixed it again, but if you see it (or other FAQs) messed up like this just do a search and replace in VFP once you have copied the code into a prg.

boyd.gif

 
I've designed a themed Datepicker (and DateTimepicker )
It is posted on UniversalThread download section id #25398
It is based on a standard VFP textbox and Montview control on a popup form
Try it, maybe you will like it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top