Solved

Validating & Using Dates

Posted on 1998-06-25
2
134 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…

895 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

16 Experts available now in Live!

Get 1:1 Help Now