Make VB.Net DatePicker Required - vb.net

I have a datepicker in a vb.net clickonce application. I need to make sure that in order to use the application that selecting a valid date is required. Ideally, I would be able to set the value of the datepicker to null and then programatically create Try Catch logic based on datepicker1.value still being null. Unfortunately, it will not allow me to assign a null or blank value to the datepicker. I cannot create my logic based on any real values of the datepicker because who's to say the value picked is not valid. I've tried setting the value to some outrageous date that no one would pick for the application like 1/1/1970, but then the datepicker opens up at 1/1/1970 and drops that date in as soon as it gains focus. I need a way to validate whether or not someone has selected a date, but am stuck and can't find any real help online. I am not looking to set the customformat = "", so please do not respond with that solution. I need the actual value to be blank or something I can run validation against to know that the user has in fact selected a date.

Set the ShowCheckBox property to true. That will make the control look like this...
When the user selects a date, it will check the checkbox. Then when you need the value...
If datePicker.Checked Then
'user has selected a value
Else
'user has NOT selected a value
End If

Can you use the ValueChanged event to set a flag to tell you they've clicked on a date?
UPDATE
You could also use the OnClick method to set a flag to verify the user actually clicked on the DateTimePicker.

Related

Access and VBA: change report text from report code

in my Access application I have a form and a report. In the form I have my textBoxForm, in the report I have my textBoxReport. Normally, in the textBoxReport I see the textBoxForm value. How can I set dynamically from the report VBA-code the value of the textReport? For example, I want that, if the value in the textForm is 1, the value in the textReport is "ok".
I have already searched a solution in internet, but in all cases I see always an error similar to 'impossible set this value for this element'.
Thank you!
Does your report use a query? If so, you would just place an 'IIF' in the query that tests for the value you want to change, then either changes it to something else, or retains the original value. The below will test field 'Nbr1' for the presence of a 1, and if found, change it to 'OK', otherwise it stays the same.
Note! You will need to change the control source in the report to reflect the name you provide (i.e. 'MyChange') because you can't keep the original name.
SELECT Table1.ID, Table1.EMPID, Table1.TestResult,
IIf([Nbr1]=1,"OK",[Nbr1]) AS MyChange, Table1.Nbr2
FROM Table1;

VB .net datetimepicker reporting wrong value

Ok, so I'm experiencing some strange behavior in datetimepicker fields in my program. I use Short format usually, and use a pair of them for date range selections.
The problem i'm experiencing is if a user is using the keyboard for input. they can tab and arrow through the field like normal to key in a date. However if the date part they are entering doesn't fill it's section of the mask and then they press enter to activate the formdefault without shifting focus away from that portion of the date, then the value of the DTP when the ok_button.click event is run is whatever value it had in it BEFORE they typed their change.
to give a specific example:
A user tabs into the date field. the default date in the field is today's date, 4/14/2015. They type in 1, arrow to the day, put in 1, then arrow to the year and type 14, then press enter. The reported value of the DTP is going to be 1/1/2015. Had they instead actually typed out 2015, or used the arrow to move to another date part or tab to shift focus to another control, the DTP will auto update to fill in the rest of the year.
The same problem would exist if they had typed in a 1 for the month and then hit enter, but would NOT happen if they put in a 12 for the month.
The only solution I can think of, and I haven't yet tried to implement it because it sounds like a real kludge and would require me to go through at TON of forms in the project, would be to change the keypress event for enter to shift focus to the OK button, and THEN invoke the formdefault.
I will say that most of the datetimepicker fields on my forms are actually contained within a user control, so if this is a property that can be changed in the control or tied to an event in the control, it would make updating much, MUCH easier.

Trying to fill textbox value with today's date only on visual basics

I am trying to fill a textbox value with the current date and I do not want the user to be able to change the date. I want to use a textbox and not a datepicker. I would like the form to load with today's date already loaded in the textbox, which I will then use in my insert query.
I want the date format of yyyy-MM-dd to be in the textbox memberregisterationdate.text. I am not sure where on my form I should put the code either.
Really stuck on this and I can't seem to find it anywhere
Thanks in advance
You have to make it Enabled = False to disable it. You can load it in Form_Load:
memberregisterationdate.Text = Date.Today.ToString("yyyy-MM-dd")

Access form: trapping date changes in textbox

On a normal textbox, I usually use the AfterUpdate event to perform some action. That means the user has to press Enter or Tab after typing, or click in another control, and I have always been happy with that behaviour.
Now I am setting up a Date filter in the header of a continuous form in Access 2010, and I realize that changing the date through the little calendar that comes automatically, does NOT fire the AfterUpdate event, forcing to press Enter after selecting the correct date, which is a bit heavy.
Using OnChange would trigger at every character entered, which is not nice either.
Any suggestion ?
It is a bit late reply but I hope it will help the others.
When using textbox as a DatePicker you should use Change Event with your filter.
However when you are checking your textbox like Form_name.TextboxName it will show last picked date. To avoid that and use currently selected one you need to provide current date like Form_name.TextboxName.Text. Careful here because .Text property is sensitive to focus.
...in short:
Form_name.TextboxName - will show last picked date
Form_name.TextboxName.Text - will show currently picked date
well, after you select a date from the date-picker, the Change event occurs for the TextBox control. Then, call a sub or function or set focus to another control... to avoid event fires for each pressed key, put something like:
if Len(me.activecontrol) < 10 then exit sub
I hope this helps
I use LostFocus event in the textbox. It allows to use the calendar tool and alter the content. The User has to leave the textbox sooner or later, isn't it?
I use it in this way
Private Sub txt_FirstDate_Change()
txt_FirstDate = txt_FirstDate.Text
myfilter
End Sub

How do I set a Calendar Object in VB.NET so that it has no date selected?

By default, the Calendar object in a VB.NET form will have 'todays date' selected.
How do I set it so that by default, it does not have a date selected whatsoever, until the user performs a click action?
Thanks,
C.
The usual method for clearing the date in a date control is to either set the value of the control to DateTime.MinValue.
Some third party controls store the value in an object and let you set the value to DBNull.Value or Nothing to indicate that no selection has been made.