Solved

CALENDAR CONTROL!! WHERE AM I GOING WRONG!?

Posted on 2004-04-19
9
394 Views
Last Modified: 2008-03-17
I have the following code for the calendar in a module. Then in the text box on my frmMember i put the following in the OnEnter: box of the date field. =OpenCalendar("frmMember","ExpiryDate",0.3,0.399)

It works on this form but when i do the same thing on date fields on other forms the calendar pops up, but when i click the date it doesnt do anything. THe calendar stays visible andthe date does not update the fields. ANY IDEAS THANKS!!!



Option Compare Database

Dim ctrl As Control
Dim frm As Form
Const centimeter = 567

 Function OpenCalendar(strForm As String, strCtrl As String, intLeft, intTop)
    Set frm = Forms(strForm)
    Set ctrl = frm(strCtrl)
        frm("Calendar5").Visible = True
        frm("Calendar5").Left = intLeft * centimeter
        frm("Calendar5").Top = intTop * centimeter
        frm("Calendar5").Value = Date
End Function

Function CloseCalendar()
    frm(ctrl.Name).SetFocus
    frm("Calendar5").Visible = False
End Function

Sub SetDate()
    frm(ctrl.Name).Value = frm("Calendar5").Value
    frm(ctrl.Name).SetFocus
    frm("Calendar5").Visible = False
End Sub
0
Comment
Question by:jam90blue
  • 5
  • 3
9 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 10863883
Change this

=OpenCalendar("frmMember","ExpiryDate",0.3,0.399)
--------------------^^^^^^^  name of the form you are using
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 10863891
and also
=OpenCalendar("frmMember","ExpiryDate",0.3,0.399)
------------------------------------^^^^^^^ make sure that the field name is correct too.
0
 
LVL 11

Expert Comment

by:phileoca
ID: 10863892
try this beauty:

'Save the Module as BasCalendar
Option Compare Database   'Use database order for string comparisons
Option Explicit

' From Access 97 Developer's Handbook
' by Litwin, Getz, and Gilbert (Sybex)
' Copyright 1997.  All rights reserved.

Const adhcCalendarForm = "frmCalendar"

Function adhDoCalendar(Optional varPassedDate As Variant) As Variant
    '
    ' This is the public entry point.
    ' If the passed in date is missing (as it will
    ' be if someone just opens the Calendar form
    ' raw), start on the current day.
    ' Otherwise, start with the date that is passed in.
   
    ' From Access 97 Developer's Handbook
    ' by Litwin, Getz, and Gilbert (Sybex)
    ' Copyright 1997.  All rights reserved.
    '
    Dim varStartDate As Variant

    ' If they passed a 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
    DoCmd.OpenForm FormName:=adhcCalendarForm, _
     WindowMode:=acDialog, OpenArgs:=varStartDate

    ' You won't get here until the form is
    ' closed or hidden.
    '
    ' If the form is still loaded, then get the
    ' final chosen date from the form.  If it isn't,
    ' return Null.
    If isOpen(adhcCalendarForm) Then
        adhDoCalendar = Forms(adhcCalendarForm).Value
        DoCmd.close acForm, adhcCalendarForm
    Else
        adhDoCalendar = Null
    End If
End Function

Private Function isOpen(strName As String, _
 Optional intObjectType As Integer = acForm)
    ' Returns True if strName is open, False otherwise.
    ' Assume the caller wants to know about a form.
    isOpen = (SysCmd(acSysCmdGetObjectState, _
     intObjectType, strName) <> 0)
End Function

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'On the date field on the form that you want use this, call the function like this (example)

Private Sub StartDate_DblClick(Cancel As Integer)

    StartDate = adhDoCalendar(StartDate)

End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
<>< kT
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

Author Comment

by:jam90blue
ID: 10864197
Hi capricorn,

i have changed that already, i must have putit in correctly as otherwise the calendar would not pop up at all.

ANyotherideas?
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 10864214
What is the name of the form and field?
Post the code you place on the
On Enter  ?
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 10864220
Is the name of the calendar on the new form Calendar5?
0
 

Author Comment

by:jam90blue
ID: 10867571
=OpenCalendar("frmCustomers2","DateOfBirth",0.199,0.199)

Like i said the form opens , but does not close when i click on it???
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 10868042
Copy and paste this codes on frmCustomers2 VBA window


Private Sub Calendar5_Click()
Call SetDate

End Sub

Check that the name of the calendar on frmCustomers2 is Calendar5
0
 

Author Comment

by:jam90blue
ID: 10869093
THANKS THAT WORKS!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question