Function ChkDate(vDate)
ret	= true
If Not (vDate = "" Or Isnull(vDate)) Then
	strPos	= 1
	I=0
	sPos	=	1
	ret	= true
	dim tmpDate()
	while (sPos >0 and Not isnull(sPos) and ret)
		sPos = instr(strpos,vDate,"/")
		if sPos = 0 Then
			EndPos	= Len( vDate)+1
		Else
			EndPos	= sPos
		End If
		Redim Preserve tmpDate(i)
		'msgbox spos
		tmpDate(i)	= Mid(vDate,strPos,endPos-strPos)
		if not isnumeric(tmpDate(i)) Then 	ret	=	false
		strPos	=	endPos+1
		I=I+1
	Wend
	If ret Then
		If UBound(tmpDate) <> 2 Then
			ret	=	false
		Else
			If tmpDate(2) < 100 Then
				tmpDate(2) = tmpDate(2) + 2500 -543
			ElseIf CInt(tmpDate(2)) >= cint(Year(date)+453) Then	'สามารถระบุวันที่ย้อนหลังได้ 90 ปีนับจากปีปัจจุบัน
				tmpDate(2)	=	tmpDate(2) - 543
			Else
				ret = false
			End If
			If ret then
				If tmpDate(1) > 12 or tmpDate(1) < 1 then ret = false
			End If
			If ret then
				if (tmpDate(0)=29 and tmpDate(1)=2) then
					if (tmpDate(2) Mod 4)>0 then	ret	=	false
				elseif not(isDate(Cstr(tmpDate(0)) & "/" & Cstr(tmpDate(1))& "/" & Cstr(tmpDate(2))) ) then
					ret	=	false
				End If
			End If
		End If
	End If
	If not ret then
		msgbox "วันที่ที่ระบุไม่ถูกต้อง"
	End If
End If
ChkDate	= ret
End Function
