Topic: DateTimePicker field

Hi all,
I'm wondering if there is a way to show a DateTimePicker field as BLANK?
.
When I have a DateTimePicker field on a form and I'm creating a new record, the Date always shows today's date.  I'd like it to be blank until I put something in it by using script.
.
Thanks
Frank

Re: DateTimePicker field

Hello papafrank

You could try this :

Form1.DateTimePicker1.Format:=' ';

JB

Re: DateTimePicker field

Jean,
.
That's perfect, works just like I wanted. And it's simple smile
.
Thanks, Frank

Re: DateTimePicker field

Jean,
Your fix for BLANKING my date picker field was working fine.  But I've been working on other things and had to go my backup copy of the program because I broke a bunch of stuff.  Sometimes I'm my worst enemy sad
.
Anyway, now I can't get your blanking fix to work.  I know without you seeing my program you would have a hard time telling me what I might be doing wrong.  But I'm wondering if there is anything you can think of that might cause it to fail?
.
I'm wondering what it is that automatically puts today's date into the date picker field when a new form is opened?  I've been looking but can't find anything.
.
Thanks for your help.
Frank

Re: DateTimePicker field

When you say it fails, what do you mean? Look at your object properties for the datetimepicker. Do you have the checked property turned on? If so, then uncheck it.

Re: DateTimePicker field

ehwagner,
The checked option is turned OFF.
.
By failing, here's what I mean.
When I open my form to add a new record, my date picker field shows Today's Date, before I have tried to put anything in it.
.
Jean was kind enough to suggest that I do the following Form1.DateTimePicker1.Format:=' ';.  When I implemented it earlier, it worked fine, the date picker was blank.  However, I've been working a number of things and now the fix has stopped working.  I most likely have done something but so far haven't been able to find the problem.
.
It looks to me like the default date for a date picker field is today's date.  And that's OK for most of my date fields but in this one case I'd like it to be blank as I'm using script to populate the field later on.
.
Thanks for looking into this for me.
Frank

Re: DateTimePicker field

Is the date on your form have the checkbox checked when you run it?

Re: DateTimePicker field

ehwagner,
I had the ShowCheckbox set to false, so there was no checkbox when I run the form.  I figured I don't need the checkbox because the user will not be putting any data into this field.  I'm doing it with a script.
.
As a test, I set ShowCheckbox to true and when I run the form the checkbox is not checked.
.
Thanks, Frank

Re: DateTimePicker field

Ok, check to make sure the script for Form1.DateTimePicker1.Format:=' '; is defined in your EVENT tab to make sure it is actually executing. It is probably in the OnShow event. Otherwise, you may need to upload your project so we can check it out.

Re: DateTimePicker field

EH,
Yes it is in the ONSHOW event for my form.
.
And I know it is executing because I was testing some options and it worked OK.
When I put in frmEquip.EqNextSvcDate.Format := '99/99/9999' ; this shows up in the date field.  However I am not able to change that date with my script.
When I go back to frmEquip.EqNextSvcDate.Format := '' ; I can update the field, but it still shows today's date when the form opens.
Also I tried frmEquip.EqNextSvcDate.Format := ' ' ; ( a space between the apostrophes )
This does blank the date field but I'm not able to change it with my script.
.
I'm pretty sure the aliens are coming in at night and messing with my code, then laughing about it smile  I don't know why because I'm a real nice guy !
.
Thanks for helping and putting up with my strange sense of humor.
Frank

Re: DateTimePicker field

Hello papafranck, hello ehwagner

My fix was working fine. Perfect.
Since then, what have you taken in action to make sure everything goes wrong? A new use with the DateTimePicker which would keep today's date by default?
If so, you could reenter the fix (Form1.DateTimePicker1.Format: = '';) in the OnShow event of the form containing the dateTimePicker Object.
Give me more details to propose a more precise solution.
Hello ehwagner, sorry when I answered I had not read your answers to papafranck which are close to mine

JB

Re: DateTimePicker field

Hi Eh & Jean,
.
Yes, the DatePicker is in the ONSHOW event.
Please refer to my last reply to EH as it explains how it's working and not working.
For some reason it doesn't like the ...Format := ''
.
I'm sorry but I can't tell you the things I have done that might have stopped it from working.  I had to go to a backup copy of my program because I was making some changes ?? and screwed up the program.  It was easier to revert to my backup than try to fix whatever I screwed up sad
.
I've just been playing around with a different approach.  Here's what I'm doing:
- My NextSvcDate will not be updated by the user so I changed it to a Text field.
- Then I'm using the DateToStr function to create the NextSvcDate.
- It looks good so far.
- I'm working on some issues related to when and how I change the NextSvcDate.
.
I'll work on it tomorrow as I've had all the fun I can stand for today smile
.
I'll update the post when I get back at it tomorrow.
.
Many thanks for all your inputs.
Frank

Re: DateTimePicker field

Frank,
See attached sample for how to blank the date (using Jean's solution). When you populate the date using script you also need to clear (nullify) the format following the date set script so the date shows. I don't know how you populate your date, but In the example I use a button to set the date. Just adapt the concept in your program.

Post's attachments

Attachment icon Blank Date.zip 335.09 kb, 205 downloads since 2021-08-24 

Re: DateTimePicker field

ehwagner,
.
Thanks for the sample program.  I've been adding it into my program and it's mostly been working.  I say mostly because I have a number of other things that are not working.  Some basic things that I've been putting off fixing, thinking that I'll fix those things later. Now I believe I should have already taken care of those items.
.
However the more I look at the overall program I'm questioning my design.  So I'm going to take a couple of steps back and see if I need to re-work or modify my design.
.
I was doing pretty good until I got into Dates and trying to create that Next Service Date.  That's when things started to go sideways. I was finding a number of "what if" scenarios that could occur with the Next Service Date.
.
Derek, Jean and yourself have given me a lot of great input about things that can be done with dates.  So I feel I'm learning and that's a good thing.

Taking all that I've learned I'm going to see about doing some fine tuning.
.
Thanks and I know I'll be back soon with questions and looking for advice.
Frank

Re: DateTimePicker field

Hi All,
.
I just wanted to give you an update on my progress.  I was finding that my program was NOT saving the Next Service Date in it's table when I was saving the record.  This was one of the weird problems I was referring to in my last post.
.
Here's what I did in case anyone has been following my adventures.
- my Next Service Date table name is EqNextSvcDate
- the name of my date picker field on my Equipment form was the same - EqNextSvcDate
I usually don't make these names the same but for some reason I did??
.
- so I changed the name of my date picker on the Equipment form to NextSvcDate
.
And now the program is saving the date - YEAH, something is finally starting to work.
.
Can anyone please tell me that making the names different is some kind of rule or is it maybe just a coincidence in my case?
.
Since this part of my program is now working, I'm going to make it my rule that I won't make the names the same in the future.
.
Thanks again for all your help with my project.  Maybe my blundering can help some other folks.
Frank

Re: DateTimePicker field

Hi All,
UPDATE: I've decided to go back to my earlier scheme of making EqNextSvcDate a TEXT field instead of a DatePicker field.
.
Even though all of your suggestions have worked in some circumstances, I have not been able to implement then for all of the "what if" scenarios in my application.
.
Here's my reasoning for this.
My EqNextSvcDate field will only contain a Date.  And it will be populated using Script. The user will never need to update or change this field. So now I don't have the problem of trying to make it BLANK.  Also I'm using the DateToStr function to calculate the date that will go into this field. So far that's working.  And its much easier to handle - at least for me.
.
If you feel this is not a sound approach, please let me know.
.
Thanks
Frank