[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 185
  • Last Modified:

Passing VB control to SQL7 db field

We have a form that contains date fields in a SQL table.  The default for the field is null.  However, once a date has been entered in the field, you cannot remove the date without then pressing Ctrl+0 to set the field back to Null.  What commands could we use to send the Ctrl+0 to the field, and which area of the date field should we put it on (LostFocus, OnExit etc).
1 Solution
1. set the focus to the control :
2. send the Ctrl+0 to the control :
   SendKeys ("^{0}"), True
julesuk71Author Commented:
We'll try your suggestion and get back to you for grading!
julesuk71Author Commented:
This is code we presently have on the Date Closed field:
Private Sub txtTaskDateClosed_lostfocus()
If txtTaskDateClosed = " " Then SendKeys ("^{0}"), True
End Sub

We have two screens - one is a summary screen, where you can select a particular record, then click a button which opens a Detail screen.  If you remove an entry from the date field in the Summary screen, it stays "gone", which is perfect.  However, if you remove the SAME date entry when you are in the Detail screen, when you return to the Summary screen, the date still appears in the field.

Any suggestions on this???
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

julesuk71Author Commented:
As we have several date fields that need the option of removing the date, it seemed silly that we should have to put code on each field to reset it to null.  There has to be a simpler and better solution than posting code on every date field that could be deleted.  
Set the dateformat field in VB for the textbox to DATE.  This will cause VB to pass a null date-type field to SQL, instead of a blank, unformatted field.
julesuk71Author Commented:
Thanks, kbakst!  That suggestion did actually work perfectly!!!
if you set the forms' textbox to be bound to the rs field (date) as a date then when there is no date given the null value is therefore passed to you data-source else a date must be given.

good luck,

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now