>Option Explicit > >Dim cDateFormat(3) As String >Private nDateFormat As DateFormat_Enum > >Enum DateFormat_Enum > YMD_Format = 1 > MDY_Format = 2 > DMY_Format = 3 >End Enum > >Public Property Get DateFormat() As DateFormat_Enum > DateFormat = nDateFormat >End Property > >Public Property Let DateFormat(pDateFormat As DateFormat_Enum) > If nDateFormat <> pDateFormat Then > With txtDate > .Text = ChangeDateFormat(.Text, cDateFormat(nDateFormat), cDateFormat(pDateFormat)) > End With > nDateFormat = pDateFormat > End If >End Property > >Function ChangeDateFormat(ByVal sDate As String _ >, ByVal cOldFormat As String, ByVal cNewFormat As String) As String > > Dim nY As Integer > Dim nM As Integer > Dim nD As Integer > > Dim cY As String > Dim cM As String > Dim cD As String > > Dim cS As String > Dim cR As String > > cS = LCase(cOldFormat) > cR = LCase(cNewFormat) > > nY = InStr(1, cS, "yyyy") > nM = InStr(1, cS, "mm") > nD = InStr(1, cS, "dd") > > cY = Mid(sDate, nY, 4) > cM = Mid(sDate, nM, 2) > cD = Mid(sDate, nD, 2) > > cR = Replace(cR, "yyyy", cY) > cR = Replace(cR, "mm", cM) > cR = Replace(cR, "dd", cD) > > ChangeDateFormat = cR > >End Function > >Sub InitDateFormat() > > cDateFormat(1) = "yyyy/MM/dd" > cDateFormat(2) = "MM/dd/yyyy" > cDateFormat(3) = "dd/MM/yyyy" > > ' begin. comment. > ' Without this code, the format will explode > ' because the element 0 of the array is empty > If nDateFormat = 0 Then > nDateFormat = YMD_Format > End If > ' end. comment. > >End Sub > >Private Sub UserControl_Initialize() > InitDateFormat >End Sub >>