Solved

CALENDAR CONTROL!! WHERE AM I GOING WRONG!?

Posted on 2004-04-19
9
392 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

813 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

10 Experts available now in Live!

Get 1:1 Help Now