Setting a date field via vb.net code


This is just a very quick post as it is always something I have to lookup so thought others may find it useful. There are several ways to get todays date in vb.net all of which are legitimate, however in order to insert them into a date combo object, or an ido property they must be formatted correctly as Syteline will not implicitly convert date formats. In our system we have additional User Fields against “Item” which hold information as to whether the item has been launched to our customers or not, and when it has been launched the date it was launched. Some of you may well think the “Status” field is sufficient for your requirements, but our customer documentation is built from our item records, so we need something to indicate whether information should be included, and amending the status field effects processing of shop floor transactions. Here is a code snipet that shows when the status is changed on the PBTI Status field it sets the date field accordingly :-

 Sub pbti_setlaunchdate()

If ThisForm.CurrentIDOCollection.CurrentItem(“itmUf_LaunchDate”).Value = “” And ThisForm.Components(“PBTI_DROP_PBTIStatus”).Value.ToUpper = “LIVE” Then ThisForm.CurrentIDOCollection.CurrentItem(“itmUf_LaunchDate”).SetValuePlusModifyRefresh(Date.Now.ToShortDateString) ElseIf ThisForm.CurrentIDOCollection.CurrentItem(“itmUf_LaunchDate”).Value <> “” And ThisForm.Components(“PBTI_DROP_PBTIStatus”).Value.ToUpper = “NOT APPROVED” Then ThisForm.CurrentIDOCollection.CurrentItem(“itmUf_LaunchDate”).SetValuePlusModifyRefresh(“”)

End If

End Sub

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.