Solved

Validating & Using Dates

Posted on 1998-06-25
2
137 Views
Last Modified: 2011-09-20
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
Comment
Question by:gordonfm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 2

Accepted Solution

by:
swilt earned 30 total points
ID: 1464246
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
 

Author Comment

by:gordonfm
ID: 1464247
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

697 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question