Solved

CALENDAR CONTROL!! WHERE AM I GOING WRONG!?

Posted on 2004-04-19
9
396 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 

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

Back Up Your Microsoft Windows Server®

Back up 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.

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
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…

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