?
Solved

Removing dates from a DateTimePicker in VB.NET?

Posted on 2009-05-12
4
Medium Priority
?
1,613 Views
Last Modified: 2013-11-26
One of the features in the program I'm working on will have the option for a user to create a daily report. The process begins with the user selecting the date they want to enter the report for. What I'd like to do is hide or exclude dates that have already been entered, since a user can't submit more than one report for the same day. Is there any way to remove a date entry from the DateTimePicker in VB.NET 2005?

If that isn't possible, I suppose the only other option is to populate a regular combobox with dates excluding those that have already been entered into the database, but I'm not sure exactly how to accurately populate a combobox with a date range.
0
Comment
Question by:elorc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 15

Expert Comment

by:ChloesDad
ID: 24367567
You can't remove a single date or dates from the date time picker. All you can do is select a min date and a max date. Using a combo box would be a bit of a pain for users as they could have to scroll through several hundred dates to find the one that they want.

I would allow them full use of the date/time picker, and then check if the date is valid either in the click event of the report generation button, or in the valuechanged event of the date time picker.

The other option is to let the user recreate the report for the date, assuming the data is available to do this
0
 
LVL 1

Author Comment

by:elorc
ID: 24367617
Well the combobox wouldn't be that bad, actually. They can't create reports for dates that occur in the future, and they can't create reports for dates prior to 01/01/2009. So in theory, they'd only see a few dates in the combo box because these reports are filled out every day. That's kind of the reason I wanted to use the approach I mentioned, because it will make it clear that they missed a day.
0
 
LVL 15

Accepted Solution

by:
ChloesDad earned 1000 total points
ID: 24368840
As long as you dont see that as a problem then populating a combo box is easy as long as you know what dates are valid for running a report. The code below will do what you want

dim startdate as date = new date(2009,1,1)
dim enddate as date = now.date
dim ReportaoDate as integer
 
datecombobox.clear
 
for ReportaoDate = startdate.toaodate to enddate.toaodate
 
if not ReportalreadyRun(ReportaoDate) then
  datecombobox.add(new date.fromaodate(reportaoDate))
endif
 
next reportaodate
 
 
The selectedItem property of the combo box will contain a date so you will need to directcast it into a date from an object to use it

Open in new window

0
 
LVL 1

Author Closing Comment

by:elorc
ID: 31580561
I ended up using something similar to this and it does the trick. Thanks for the clarification.
0

Featured Post

CHALLENGE LAB: Troubleshooting Connectivity Issues

Goal: Fix the connectivity issue in the lab's AWS environment so that you can SSH into the provided EC2 instance.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question