try (line 28)BUT the minutes are always off.
fieldTime = Format(Now, "hh:nn")
Private Sub lastControl()
'Store the last field used before opening this form
lastFrm = Screen.ActiveForm.Name
lastCtl = Screen.ActiveControl.Name
fieldTime = Format(Forms(lastFrm).Form(lastCtl), "Short Time")
End Sub
Look at this version pleaseHere is a seems to be working version....
Private mCallingControl As Access.Control
Public Property Get CallingControl() As Access.Control
Set CallingControl = mCallingControl
End Property
Public Property Set CallingControl(ByVal TheControl As Access.Control)
Set mCallingControl = TheControl
End Property
Dim frm As Access.Form
DoCmd.OpenForm "TimePicker_v002", , , , , , sOpenArgs$
Set frm = Forms("TimePicker_v002")
'pass in the calling control
Set frm.CallingControl = Me.txtTimeShort
'verify it works.
MsgBox frm.CallingControl.Name
Public Function fncShowTimePicker(ByRef txt As TextBox)
'Purpose: Open the time picker form, identifying the text box to return the length to.
'Arguments: txt = the text box to return the time to.
Set gtxtTimeTarget = txt
DoCmd.OpenForm FormName:="frm_TimePicker"
Dim frm As Access.Form
Set frm = Forms("frm_timePicker")
Set frm.CallingControl = txt
End Function
Option Compare Database
Option Explicit
Dim intHours As Integer, intMinutes As Integer
Private mCallingControl As Access.Control
Public Property Get CallingControl() As Access.Control
Set CallingControl = mCallingControl
End Property
Public Property Set CallingControl(ByVal TheControl As Access.Control)
Set mCallingControl = TheControl
SetTime
End Property
Private Sub cmdConfirm_Click()
Me.CallingControl.Value = Me.txtTargetTime.Value
DoCmd.Close acForm, Me.Name
End Sub
Private Sub cmdClose_Click()
DoCmd.Close
End Sub
Private Sub SetTime()
Dim intStartPos As Integer
Dim varTargetTime As Date
'Get the time from the previous form if it exists _
and if not use the current time for the varTargetTime
If Not IsDate(Me.CallingControl.Value) Then
varTargetTime = Format(Now, "HH:MM")
Else
varTargetTime = CallingControl.Value
End If
intStartPos = IIf(Mid(varTargetTime, 2, 1) = ":", 1, 2)
intHours = Left(varTargetTime, intStartPos)
Me![optGroupHours] = intHours
intMinutes = Mid(varTargetTime, intStartPos + 2, 2)
Me![OptGroupMinutes] = intMinutes
'Update this forms textbox txtTargetTime
Call updateTargetTime
End Sub
Private Sub optGroupHours_Click()
intHours = Me!optGroupHours
Call updateTargetTime
End Sub
Private Sub OptGroupMinutes_Click()
intMinutes = Me!OptGroupMinutes
Call updateTargetTime
End Sub
Private Sub updateTargetTime()
Me.txtTargetTime = Format(intHours, "00") & ":" & Format(intMinutes, "00")
End Sub
Private mCallingControl As Access.Control
Public Property Get CallingControl() As Access.Control
Set CallingControl = mCallingControl
End Property
Public Property Set CallingControl(ByVal TheControl As Access.Control)
Set mCallingControl = TheControl
SetTime
End Property
Private Sub cmdConfirm_Click()
Me.CallingControl.Value = Me.txtTargetTime.Value
DoCmd.Close acForm, Me.Name
End Sub
Private Sub cmdClose_Click()
DoCmd.Close
End Sub
Private Sub SetTime()
Dim varTargetTime As Date
'Get the time from the previous form if it exists _
and if not use the current time for the varTargetTime
If Not IsDate(Me.CallingControl.Value) Then
varTargetTime = DateSerial(Year(Now), Month(Now), 0)
Else
varTargetTime = CallingControl.Value
End If
Me.txtTargetTime = varTargetTime
Me![optGroupHours] = Hour(varTargetTime)
Me![OptGroupMinutes] = Minute(varTargetTime)
End Sub
Private Sub optGroupHours_Click()
Me.txtTargetTime = TimeSerial(Me.optGroupHours, Minute(Me.txtTargetTime), 0)
End Sub
Private Sub OptGroupMinutes_Click()
Me.txtTargetTime = TimeSerial(Hour(Me.txtTargetTime), Me.OptGroupMinutes, 0)
End Sub