Here's what I use. Some of it was "leveraged" :-) from somewhere and then
modified. This has been in one of my production apps for over 9 years.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Code in calendar popup form:
Private Sub cmdClose_Click()
DoCmd.Close
End Sub
Private Sub cmdOK_Click()
Me.Visible = False
End Sub
Private Sub Form_Load()
If IsNull(Me.OpenArgs) = False Then
Me!axCalendar = Me.OpenArgs
Else
Me!axCalendar = Date
End If
End Sub
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Code for command buttons:
Private Sub cmdEndDate_Click()
DateCheck txtEndDate
txtEndDate.SetFocus
End Sub
Private Sub cmdStartDate_Click()
DateCheck txtStartDate
txtStartDate.SetFocus
End Sub
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Code in a standalone module:
Public Sub DateCheck(ctlDate As TextBox)
Dim varDatePassed As Variant
Dim varReturn As Variant
varDatePassed = ctlDate
varReturn = GetDate(varDatePassed)
If IsNull(varReturn) = False Then
ctlDate = varReturn
End If
End Sub
Private Function GetDate(Optional varDate As Variant) As Variant
' If varTempDate is missing then use today's date.
' Otherwise, set the date to the date passed.
Dim varTempDate As Variant
' Set calendar date
varTempDate = IIf(IsMissing(varDate), Date, varDate)
' Validate date
If Not IsDate(varTempDate) Then varTempDate = Date
DoCmd.OpenForm FormName:="fdlgCalendarControl", WindowMode:=acDialog,
OpenArgs:=varTempDate
' If fdlgCalendarControl is still loaded, then the user clicked OK so
get the
' date from the form. If the form isn't open return a value of Null.
If IsFormLoaded("fdlgCalendarControl") Then
GetDate = Forms("fdlgCalendarControl").axCalendar.Value
DoCmd.Close acForm, "fdlgCalendarControl"
Else
GetDate = Null
End If
End Function
Private Function IsFormLoaded(ByVal strformName As String) As Boolean
Const conObjStateClosed = 0
Const conDesignView = 0
If SysCmd(acSysCmdGetObjectState, acForm, strformName) <>
conObjStateClosed Then
If Forms(strformName).CurrentView <> conDesignView Then
IsFormLoaded = True
End If
End If
End Function
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enjoy and good luck.
Sco
M.L. "Sco" Scofield, Microsoft Access MVP, MCSD, MCP, MSS, A+
Useful Metric Conversion #18 of 19: 8 nickels = 2 paradigms (My personal
favorite)
Miscellaneous Access and VB "stuff" at www.ScoBiz.com
> Hello, I created a little form to serve as a custom date picker popup, and I
> wanted to make it generic enough to be used in several places in my database.
[quoted text clipped - 21 lines]
> ' Code that returns a value something like this:
> '
Forms("MasterFormName").Form.Controls("ChildFormName").Form("txtDate1")
> End Function
>
> Can this be done? I could use it elsewhere, too!
code - 04 Jan 2005 15:35 GMT
Hello, Yes! That is what I was looking for. Very nice and clean, all fully
typed, excellent work! I will probably also use varations of this for years!
Thank you very much!
--Jon
> Here's what I use. Some of it was "leveraged" :-) from somewhere and then
> modified. This has been in one of my production apps for over 9 years.
[quoted text clipped - 143 lines]
> >
> > Can this be done? I could use it elsewhere, too!
M.L. Sco Scofield - 04 Jan 2005 22:52 GMT
You're most welcome.
Sco
M.L. "Sco" Scofield, Microsoft Access MVP, MCSD, MCP, MSS, A+
Useful Metric Conversion #18 of 19: 8 nickels = 2 paradigms (My personal
favorite)
Miscellaneous Access and VB "stuff" at www.ScoBiz.com
> Hello, Yes! That is what I was looking for. Very nice and clean, all fully
> typed, excellent work! I will probably also use varations of this for years!
[quoted text clipped - 150 lines]
> > >
> > > Can this be done? I could use it elsewhere, too!
You can also look at my solution here:
http://www.pointltd.com/Downloads/Details.asp?dlID=32

Signature
Alex Dybenko (MVP)
http://Alex.Dybenko.com
http://www.PointLtd.com
> Hello, I created a little form to serve as a custom date picker popup, and
> I
[quoted text clipped - 29 lines]
>
> Can this be done? I could use it elsewhere, too!