troubleshooting Question

pass form name and control name to procedure

Avatar of Sandra Smith
Sandra SmithFlag for United States of America asked on
Microsoft AccessMicrosoft ApplicationsMicrosoft Development
14 Comments1 Solution468 ViewsLast Modified:
I have a calendar procedure that works well.  However, since I use it in so many forms, I was trying to get it to be one called procedure passing only the form name and control name to it.  HOwever, I keep getting a "The control number you speciifed is greater than teh number of controls". which I have no ide means. I am calling the procedure by using the below.  Also, can this even be done?

Private Sub HRStartDate_Click()
    Call ShowCalendar(Me, Me.HRStartDate)
End Sub

The actual procedure is:

Public Sub ShowCalendar(frmName As Form, ctlName As Control)
'Used for the MonthCalendar control
Dim blRet As Boolean
Dim dtStart As Date
Dim dtEnd As Date
Dim ctl As Control

'First check to see if the control is locked, if it is, then cannot show
'calendar as field should not be changed.

If frmName.Controls(ctlName).Locked = True Then
    Exit Sub
End If

dtStart = Nz(frmName.ctlName.value, 0)
dtEnd = 0

blRet = ShowMonthCalendar(mc, dtStart, dtEnd)
If blRet = True Then
    frmName.ctlName = dtStart
Else
' Add any message here if you want to
' inform the user that no date was selected
End If
End Sub

PS:  This is code from, I think Allen Browne's site, it works as he originally created, I am just trying to ttake it a step further.
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 14 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 14 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros