Popup Calendar

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Using MS Office 2003 Pro
I am trying to add a popup calendar to a subform to enable users to select
date vice typing it in a date field. I have done this on several forms, but
cannot get it to work on the subform. I get "error msg 2110 MS ACCESS can't
move the focus to the control DateCalendar " Here is code that works on forms:

Private Sub TransactionDate_MouseDown(Button As Integer, Shift As Integer, X
As Single, Y As Single)
DateCalendar.Visible = True
DateCalendar.SetFocus
If Not IsNull(TransactionDate) Then
DateCalendar.Value = TransactionDate.Value
Else
DateCalendar.Value = Date
End If
End Sub

Is there a way to get this to work on the subform?

Thanks
 
Hi, Shep.

If the TransactionDate text box resides on the main form and the
DateCalendar calendar control resides on the subform, then find out the name
of the subform control. This is _not_ the name of the subform, unless you've
made the mistake of naming them the same. Whenever the main form is open,
the subform _doesn't_ exist. It's being "held" by a special control on the
form, the subform control, which must be referenced as a control before any
of the controls residing on it can be referenced.

Therefore, if the TransactionDate text box resides on the main form and the
DateCalendar calendar control resides on the subform, then try:

Private Sub TransactionDate_MouseDown(Button As Integer, Shift As Integer, X
As Single, Y As Single)
Me!MyCtrl.Form.DateCalendar.Visible = True
Me!MyCtrl.Form.DateCalendar.SetFocus
If Not IsNull(Me!TransactionDate.Value) Then
Me!MyCtrl.Form.DateCalendar.Value = Me!TransactionDate.Value
Else
Me!MyCtrl.Form.DateCalendar.Value = Date
End If
End Sub

.. . . where MyCtrl is the name of the subform control.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.
 
Don't reinvent the wheel...I just asked this exact question three days ago
and got some great ideas, the best of which I felt could be found at and
downloaded for free from http://allenbrowne.com/ser-51.html

Allen's got a great Access site that is now in my favorites list.

Good luck!
 
:
Thanks for your response
The date field and calerndar control are on the subform. Your explanation
about the subform's status when the form is open may be why it is not setting
focus of the calendar control. It may be that the setfocus function is
controlled by the form.

Hopefully there is a way to code it so the calendar will work on the subform.

Thanks again for your help.
 
Did you get a popup calendar to work on a subform? If so, will you share the
code with me?

Thanks
 
Hi, Shep.

If both the date text box and the calendar control are on the subform, then
your code should work, unless you wrote code elsewhere -- or changed the
calendar control's property -- that interferes with this.

Did you disable the calendar control? Check the DateCalendar's "Data" tab
in the Properties dialog window. The Enabled Property should be set to Yes.
If it is, then search through the code for the following:

DateCalendar.Enabled = False

The DateCalendar must be enabled when the focus is set to it. If you can't
find where it's been disabled, then in your subform's module try:

Private Sub TransactionDate_MouseDown(Button As Integer, Shift As Integer, X
As Single, Y As Single)
DateCalendar.Visible = True
DateCalendar.Enabled = True
DateCalendar.SetFocus
If Not IsNull(TransactionDate) Then
DateCalendar.Value = TransactionDate.Value
Else
DateCalendar.Value = Date
End If
End Sub

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.
 
The calendar Darhl refers to works on any level of subform.

Just use the name of the text box in the Click event of the button,
regardless of whether it is in a main form or a subform.
 
Thanks for your response. I did get your calendar to work on forms, but on
this subform the icon did not show. I think I have a gremlin in this subform.

Thank you
 
I did get your calendar to work on a form, but on this subform the icon did
not show. I think I have a gremlin in this subform. More likely I have met
the enemy and it is me.

Thanks for your help.
 
Thanks again for your help; however, I still cannot get the focus set. There
must be something in the other code on this subform blocking the action. I
did get Arvin Meyer's calendar to work on the subform.

Would you like me to send all the subform code so you might solve this
enigma? It is not too extensive.

Thanks
 
Thank you, your calendar works on the subform. When I move the pointer over
the calendar it changes to a vertical bar. Is that normal or maybe something
in my mouse setting? Regardless, it works great.

Many thanks
 
Hi, Shep.
Would you like me to send all the subform code so you might solve this
enigma?

Feel free to post the code, but seeing as you've already found a better
alternative, you probably shouldn't be losing sleep over this one. You've
got plenty of other fish to fry, so you should spend your time on those.

Good luck.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.
 
shep said:
Thank you, your calendar works on the subform. When I move the pointer over
the calendar it changes to a vertical bar. Is that normal or maybe something
in my mouse setting? Regardless, it works great.

Each of the dates is in a tiny text box, so yoy will get that cursor
behavior. You could mess with the mouse over event and maybe change it. The
code is wide open to use or change.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads
http://www.datastrat.com
http://www.mvps.org/access
 
I am posting the code in case you have time to explore. I just don't
understand why the MS Cal is not working in this subform. However, I agree
that it is not critical since there are alternatives.

Thanks again to you and others who have helped.
Best Regards

Code ( this is from the MS template Inventory Control, to which I added the
calendar code).

Option Explicit
Option Compare Database


Private Sub ViewPurchaseOrders()
On Error GoTo Err_ViewPurchaseOrders
If IsNull(Forms![Products]![ProductID]) Then
MsgBox "Enter product information before entering purchase order."
Else
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
DoCmd.OpenForm "Purchase Orders"
If Me![PurchaseOrderID] > 0 Then
DoCmd.GoToControl "PurchaseOrderID"
DoCmd.FindRecord Me![PurchaseOrderID]
Else
If Not IsNull(Forms![Purchase Orders]![PurchaseOrderID]) Then
DoCmd.DoMenuItem acFormBar, 3, 0, , acMenuVer70
End If
End If
End If

Exit_ViewPurchaseOrders:
Exit Sub

Err_ViewPurchaseOrders:
MsgBox Err.Description
Resume Exit_ViewPurchaseOrders
End Sub

Private Sub DateCalendar_Click()
TransactionDate.Value = DateCalendar.Value
TransactionDate.SetFocus
DateCalendar.Visible = False
End Sub

Private Sub TransactionDate_DblClick(Cancel As Integer)
ViewPurchaseOrders
End Sub
Private Sub PurchaseOrderID_DblClick(Cancel As Integer)
ViewPurchaseOrders
End Sub

Private Sub TransactionDate_MouseDown(Button As Integer, Shift As Integer, X
As Single, Y As Single)
DateCalendar.Visible = True
DateCalendar.SetFocus
If Not IsNull(TransactionDate) Then
DateCalendar.Value = TransactionDate.Value
Else
DateCalendar.Value = Date
End If
End Sub

Private Sub TransactionDescription_DblClick(Cancel As Integer)
ViewPurchaseOrders
End Sub
Private Sub UnitsOrdered_DblClick(Cancel As Integer)
ViewPurchaseOrders
End Sub
Private Sub UnitsReceived_DblClick(Cancel As Integer)
ViewPurchaseOrders
End Sub
Private Sub UnitsSold_DblClick(Cancel As Integer)
ViewPurchaseOrders
End Sub
Private Sub UnitsShrinkage_DblClick(Cancel As Integer)
ViewPurchaseOrders
End Sub
 
Back
Top