Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 143
  • Last Modified:

Validating & Using Dates

I'm using an Access database with VB5 to store information on customers requirements for price lists.  I'm going to need to use dates fairly heavily in my app.  
Is it best to use the masked edit box to process input the date?  I have played around with it a little but had problems trying to assign it properly to a control (I'm using unbound controls).
I have toyed with the IsDate function, but that relies on the user entering the slashes for the date (eg - 26/06/98).  
Any suggestions as to the best way to enter a date field and use it in the database?

Regards

Gordon    
0
gordonfm
Asked:
gordonfm
1 Solution
 
swiltCommented:
Use a masked edit box with mask = "##/##/##"
When assigning the masked edit box use

Option Explicit

Private Sub Form_Load()
    AssignDate MaskEdBox1, #12/2/98#
End Sub

Private Sub AssignDate(m As MaskEdBox, sDate As String)
    Dim sMask As String

    sMask = m.Mask
    m.Mask = ""
    sDate = sReplace(Format$(sDate, "Short Date"), ".", "/")
    If Len(sMask) = 8 Then
        sDate = Left$(sDate, 6) & Right$(sDate, 2)
    End If
    m.Text = sDate
    m.Mask = sMask
End Sub

Private Function sReplace(ByVal sInp As String, ByVal sChar As String, ByVal sRepl As String) As String
    Dim p As Integer
   
    p = InStr(sInp, sChar)
    While p > 0
        Mid$(sInp, p) = sRepl
        p = InStr(sInp, sChar)
    Wend
    sReplace = sInp
End Function

0
 
gordonfmAuthor Commented:
Thanks for your great answer.  I would never have got any where that code....

Thanks again.  I'm about to place it in my prog.

Regards

Gordon  
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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