?
Solved

Validating & Using Dates

Posted on 1998-06-25
2
Medium Priority
?
140 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 120 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

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.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses

764 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