[AccessD] How do I pass a control to a function in the ControlSource

Max Wanadoo max.wanadoo at gmail.com
Wed Sep 30 18:48:17 CDT 2009


Hi Jurgen,

This is what =Popcal(true/False) will call.  Hope it makes sense.

Max


Function PopCal(bAllowEdit As Boolean) As Variant  'Boolean
' calls the calendar with a flag to indicate if dates can be edited
  If gbMcmModuleLogging = True Then Call mcmModuleLogging("MCM_Calendar",
"PopCal", True)
  Dim ctl As Control, varCurValue As Variant
  On Error GoTo errhandler
  Set ctl = Screen.ActiveControl  ' this will determine which date control
was clicked on
  varCurValue = ctl.Value
  ' Uncomment one of the other of the u/m, depending on whether you want to
allow null
  ' dates or default to today's date
  '  Screen.ActiveControl = Nz(modDoCalendar(varCurValue, bAllowEdit),
Nz(varCurValue, Date))
  PopCal = Nz(modDoCalendar(varCurValue, bAllowEdit), varCurValue)
  Screen.ActiveControl = PopCal
exithere:
  If gbMcmModuleLogging = True Then Call mcmModuleLogging("MCM_Calendar",
"PopCal", False)
  Exit Function
errhandler:
  MsgBox "Error in MCM_Calendar.PopCal: " & Err.Number & vbCrLf &
Err.Description
  Resume exithere
End Function


Private Function modDoCalendar(Optional varpasseddate As Variant, Optional
bAllowChanges As Boolean) As Variant
' if bAllowChanges is not passed in then the default is False (ie, user
cannot change date)
  If gbMcmModuleLogging = True Then Call mcmModuleLogging("MCM_Calendar",
"modDoCalendar", True)

  Dim varStartDate As Variant, strOpenArgs As String

  On Error GoTo errhandler
  ' If they passed a date value at all, attempt to use it as the start date.
  varStartDate = IIf(IsMissing(varpasseddate), Date, varpasseddate)

  ' OK, so they passed a value that wasn't a date.    ' Just use today's
date in that case, too.
  If Not IsDate(varStartDate) Then varStartDate = Date
  strOpenArgs = varStartDate & "=" & IIf(bAllowChanges, "Yes", "No")
  DoCmd.OpenForm FormName:=conCalendarFormName, WindowMode:=acDialog,
OpenArgs:=strOpenArgs

  ' If the form is still loaded, then get the final chosen date from the
form.
  ' If it isn't, return Null.
  If (SysCmd(acSysCmdGetObjectState, acForm, (conCalendarFormName)) <> 0)
Then
    modDoCalendar = Forms![MCM_Calendar]![MCM_CalendarSub]!TextValue
    DoCmd.Close acForm, conCalendarFormName
  Else
    modDoCalendar = Null
  End If
exithere:
  If gbMcmModuleLogging = True Then Call mcmModuleLogging("MCM_Calendar",
"modDoCalendar", False)
  Exit Function

errhandler:
  MsgBox "Error in MCM_Calendar.modDoCalendar: " & Err.Number & vbCrLf &
Err.Description
  Resume exithere
End Function




More information about the AccessD mailing list