VB.NET - Date Time Picker saves current date by default, even if no date is chosen - vb.net

I have a date picker named 'paidDateDp' in my form. My configuration is as below
Property Setting:
Format="Custom"
Private Sub paidDateDp_ValueChanged(sender As Object, e As EventArgs) Handles paidDateDp.ValueChanged
paidDateDp.CustomFormat = "dd-MMM-yyyy"
End Sub
While executing, I see the paidDateDp value is blank. Even if I dint choose any value, when I attempt to save the details of the form to MSAccess using my Oledbadapter query, by default, the current date is getting saved against the paidDate column of my access table.
How to save empty date to my access table from my datetime picker, provided no date is selected?
Someone please suggest me.

Related

How to timestamp Each Field Updated in another assigned Field Ms Access

I'm setting up a database to monitor/timestamp the time of edit for each field (not just the form). so entered the following code in the "after update" event of the property:
Private Sub DReceived_AfterUpdate()
Me![CLASS] = Now()
End Sub
I had hoped that the edit of the field labeled "CLASS" would timestamp in the field "DReceived" but that is not happening.
I have tried "now()" function in the property of the table field but it keeps fixing the current time and date even without anything update. (I ONLY WANT A TIMESTAMP WHEN DATE In Any Field is updated
Private Sub DReceived_AfterUpdate()
Me![CLASS] = Now()
End Sub
If I have fields A to F in a table, if I edit A, B should Timestamp, C; D should TimeStamp, etc.
Use a Before Change Data Macro, not a VBA sub on a form. For one, subs won't trigger if one directly edits the table, and data macros are intended primarily to do this.
The macro would incorporate logic like:
If Updated("CLASS") Then
SetField
DReceived
=Now()

All elements of an array cannot be accessed from a for loop in monthCalendar Control - Visual Basic

I have a bit of an issue here with the monthCalendar Control in Visual Basic. What is happening in the program is I have a calendar and a text box. The user selects a date on the calendar, then types in information into the textbox component, then presses the add button. From there the add button sets up a parallel array that contains the selected date and the added string from the text box as a way to add planner information for each date. Then the date is bolded for each time an addition like this has happened.
From there you are suppose to be able to click each bolded date and view the information you added. The issue is this only works on the last added date. For some reason it will only read the last element added to the array. I have the for loop down below. I do not understand why I cannot select any bolded date and view the text added. I have option strict on so I know no data loss is occurring. Also I know the date is being selected and placed into the string each time a date is selected on the calendar because I am displaying it onto a label each time. What is the problem. Is it some logical error I am not catching or is it something else?
Public Sub MonthCalendar1_DateChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MonthCalendar1.DateChanged
For index As Integer = 0 To intSizeOfSelectedDatesAry - 1
strSelectedDay = CStr(MonthCalendar1.SelectionRange.Start) ' place the selected date into a string
lblError.Text = strSelectedDay
lblError.Visible = True
Dim strAryDate As String = arySelectedDates(index)
If (arySelectedDates(index) = strSelectedDay) Then
lblInstructions.Text = strSelectedDay
lblSelectedDate.Text = aryTextForDates(index)
index = intSizeOfSelectedDatesAry - 1
End If
Next
End Sub

Display SQL time field on Access form as Access medium time hh:mm am/pm

I am using Access 2010 linked to SQL Server 2008 R2. My problem - how do I display time on an Access form as hh:mm am/pm instead of SQL Server's time(7) format of hh:mm:ss.nnnnnnn?
To complicate things, I do have a look-up table with all the times in half hour time frames? Ex. in SQL, the lookup field says 07:30:00.0000000 - I want to choose a time from the dropdown in my Access form that says 7:30 am and then display it on the Access form as 7:30 am. If I choose it, I want it to store in SQL Server as 07:30:00:0000000 (because I have no other choice).
I can't find anything on this.
Access doesn't have a Time data type, so when it links to a SQL Server time column it maps that column as Text. That's why any Date/Time Format specifier you try to apply to the linked table value has no effect: as far as Access is concerned it's a string.
So if we have a SQL Server table [Appointments]:
and we create a Linked Table in Access we get
If we create an Access form for that linked table and use plain old bound controls we get this
The text box for [apptStart] does work, but it doesn't look so great. The workaround is to leave that text box on the form, but hide it (set its .Visible property to No) and then add another unbound text box to the form. (In this case I called it [txtStartTime].) Set the .Format of the new text box to Medium Time and adjust any other formatting as required (e.g., I set Text Align to Left).
In the On Current form event, calculate the Access Date/time value corresponding to the start time in SQL Server table and stuff that value into the [txtStartTime] text box. Now we get something that looks a little better:
Now what if the user wants to edit that value? In the After Update event for the [txtStartTime] text box we create the corresponding SQL Server time string and stuff that value into the (invisible, bound) [apptStart] text box. When the record is saved the new time value is updated in the SQL Server table.
The code behind the form is as follows:
Option Compare Database
Option Explicit
Const accessDate0 = "1899-12-30 " ' <- note trailing space
Dim startTimeAsDateTime As Date
Private Sub Form_AfterUpdate()
Me.Requery
End Sub
Private Sub Form_Current()
Me.txtStartTime.Value = CDate(accessDate0 & Left(Me.apptStart, 8))
End Sub
Private Sub txtStartTime_AfterUpdate()
Me.apptStart.Value = Format(startTimeAsDateTime, "hh:nn:ss")
End Sub
Private Sub txtStartTime_BeforeUpdate(Cancel As Integer)
On Error GoTo txtStartTime_BeforeUpdate_Error
startTimeAsDateTime = CDate(accessDate0 & Me.txtStartTime.Value)
Exit Sub
txtStartTime_BeforeUpdate_Error:
MsgBox "Start Time appears to be invalid."
Cancel = True
End Sub
Sorry, I don't have a dev environment setup, but can you change your SQL query to:
SELECT Convert(varchar(5), getdate(), 108)
to give HH:MM and truncate the rest so it displays correctly.
Then, you can cast as date on the way back.

Windows Phone DatePicker doesn't update its Value

I make a windows phone 7.8 app and i'm using a datepicker.
When i load the page that contains the datepicker, i pass the date and is displayed correctly.My code is:
Protected Overrides Sub OnNavigatedTo(ByVal e As System.Windows.Navigation.NavigationEventArgs)
Dim mydate As String = Nothing
If NavigationContext.QueryString.TryGetValue("date", mydate) Then
eventdate = Date.Parse(mydate)
datePicker.Value = eventdate
EndIf
End Sub
But when i try to change the date , the datepicker doesn't hold the new date. Does anybody know why?
Your problem is due to the way you're not correctly managing the page lifecycle.
When you go to the date selector this is actually a separate page. When tapping the "tick" to confirm the new data selection you'll return to your page. Based on your code above, at this point you'll load the date from the NavigationContext again and so the selected date is lost.
The solution is to query the NavigationEventArgs and only read the query string when the NavigationMode is New.

Binding combobox selected value to a specific column of current row (not a datagridview)

I have a database that I am using in a VB 2010 project. What I did was removed a textbox for a database field that I dragged onto the form and replaced it with a combobox. The field name was orderstatus.
The problem is this: since I removed the textbox field from the form, I can't seem to bind the combobox value to the field in the active record. In other words, orderstatus textbox doesn't exist anymore. I want to let the user pick a status from the combobox and store that value to orderstatus so that it's saved to the current record my database.
I want to do something like this:
Private Sub Button16_Click_1(sender As System.Object, e As System.EventArgs) Handles Button16.Click
orderstatus = ComboBox13.SelectedValue
Me.OrdersDataSet.orders(0).orderstatus = orderstatus
Me.Validate()
Me.OrdersBindingSource.EndEdit()
Me.TableAdapterManager12.UpdateAll(Me.OrdersDataSet)
End Sub
but it doesn't like my second line where I try to assign the value to the field, saying there is no row 0. All I want to do is put the selected value of the combobox into the orderstatus field of the record being created (or updated).
I've also tried using:
Me.OrdersDataSet.orders.orderstatusColumn = orderstatus
and I get a message saying that the property of the column is ReadOnly. I'm not sure how that's possible because I configured the dataset to update, etc.
I should probably mention that I'm not using a datagridview but a details view, if that makes a difference. I've seen some talk about how to do this using datagridview and don't know if that would work in my case.
What am I doing wrong? What should I use to update just the column I want in the current row?
Ugh, turns out I had forgot to set the databinding properties of the field in question to save directly to the binding source and also select the selecteditem to bind. It was right there and I didn't realize. Ya live and learn. :)