Solved

Validating & Using Dates

Posted on 1998-06-25
2
133 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
2 Comments
 
LVL 2

Accepted Solution

by:
swilt earned 30 total points
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now