Click to See Complete Forum and Search --> : DatePicker - I need a Guru!!
turfbult
Aug 14th, 2000, 09:37 AM
Hi,
Can someone please help me to bind my datepicker to my database fields OR maybe another suggestion to make this work....
This is my code from which I get an error "Cannot bind....."
Set DTPickerStart.DataSource = rsRecord
DTPickerStart.DataField = "start_date"
All I want to do is have the user select a start and end date which must be written away to my table - at a later stage I want to subtract end-date from start-date to get the days.
All of this works fine, but I cannot get my app. to write the datepicker values to the table!!
Please help - I've been battling with this for weeks now and cannot get it going!!
DrewDog_21
Aug 14th, 2000, 10:47 AM
That error happens in my project if the recordset is empty and the DateTime picker doesn't have that gay little checkbox. If you set the checkbox property to true or if the recordset is not empty then it will bind with no problem. I have reported this problem to Microsoft.
turfbult
Aug 14th, 2000, 11:13 AM
Seems like we're getting somewhere!!
If you can just let me know what checkbox you are talking about - my recordset definitely has data in.
Must I add a checkbox or what??
Thanks for your help so far!!
DrewDog_21
Aug 14th, 2000, 11:32 AM
Look in the Properties window at design time and set the CheckBox property to True. Or at run time, use the code DateTimePicker1.CheckBox = True
The problem with this is that when the checkbox is checked, the date value is added to the recordset. But if it is not checked then the date value is not added. I have a table with a required Date field, and if the user tries to save the data with the checkbox unchecked, an error occurs. It is retarded that I have to have the checkbox for a required field. I have reported this bug to Microsoft but I don't think they have done anything so far.
But if your recordset has data, then you should not be having this error. Put a statment like "Debug.Print myRS.RecordCount" or "MsgBox myRS.RecordCount" before you try to bind to the DTPicker and make sure that your SQL is executing correctly. Also, that same error occurs if you use a DataField name (in your case, "start_date") that either does not exist in the table or has not been selected in the SQL statement.
turfbult
Aug 14th, 2000, 02:25 PM
I'm back!!
I set the checkbox property to true and now dont get the binding error anymore, but get an error saying that I cannot insert a null into my field in the table (I set the required option to yes) HOWEVER - just before I bind the datepicker fields I can see (using debug.print) that there IS values in the datepicker.value!! I even set a textbox = dtpicker.value to double check that it does have a value. I also tried to bind the textbox(after setting it equal to the dtpicker.value) to my table, but still get the error - cannot insert a null!!
PLEASE - this is REALLY getting me down!!
DrewDog_21
Aug 14th, 2000, 04:58 PM
Yep, that's the problem with the DTPicker and required fields. The DTpicker will hold a value but if the checkbox is not checked then it will not save that value in the database, and an error occurs. Try putting a predetermined date value in your table (if you are using Access, open the table in design mode, highlight the field, and enter a either a specific date or the function Date() in the Predetermined Value box). Also it might help to set the value of the DTPicker when the user invokes the Add command, e.g. DTPicker1.Value = Now
turfbult
Aug 15th, 2000, 01:11 AM
Thanks for all your help DrewDog_21..
I've given up on the datepicker idea and just added a combobox with the date-ranges I want - It doesn't look HALF as nice but hey, the job's gotta be completed!!
I'll definitely play around with it again and see what I can do!!
JHausmann
Aug 15th, 2000, 11:36 AM
The problem's not with the datepicker control but how you're trying to use it. You could always use the control "un-bound". More code but it works...
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.