Solved

CALENDAR CONTROL!! WHERE AM I GOING WRONG!?

Posted on 2004-04-19
9
388 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 119

Expert Comment

by:Rey Obrero
ID: 10863883
Change this

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

Expert Comment

by:Rey Obrero
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
 

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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 119

Expert Comment

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

Expert Comment

by:Rey Obrero
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 119

Accepted Solution

by:
Rey Obrero 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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now