Allen Browne Popup Calendar question

Christine Pearc

Christine
Local time
Today, 04:54
Joined
May 13, 2004
Messages
111
I'm *finally* getting around to getting rid of the ActiveX calendar control in my application. After doing battle with references on other users' systems, the ocx references have finally lost the plot and don't work.

I've downloaded Allen's popup calendar but have a problem since the app uses text boxes, and I need to add the selected date into a table with date fields. Also, instead of clicking an icon (where his instructions say to put "=CalendarFor(SaleDate],...", in my previous code I just call the calendar form from the on click event when the user clicks the date field.

I've tried modifying Allen's code to no avail, and I'm afraid of really cocking things up in all my forms, tables, reports, etc. if I change all may table's date fields to text.

Could someone help me modify the code from text fields to dates? Alternatively, is there any other calendar popup out there that would suit? (I've looked at all of them in the links but haven't found anything.)

Thank you,
Christine
 
I've not tried Allen's calendar yet but he is a top notch MVP and I refer to his site often. Have you looked here yet?
 
Yes, I have looked at that link, RG. There's lots of great stuff, but Alan's looked the simplest for me to deal with - save the trouble with the text vs. date definitions. I'm really hoping someone can help me soon, as I've had to take my application off-line whilst I try to figure something out!
Christine
 
I have never used those but I suggest you check out one of these custom [Non ActiveX] Access calanders for you can import them right into your database...

Popup Calendar - Version 3

I prefer the authors first calendar because I do not want the fancy three months options. Here is the link to that one... Popup Calendar

Place this in the OnClick event of your button [or your custom OnClick event] to open [call] the calander I mentioned above...

Code:
=opencalendar("","YourTextBoxNameHere")

It will work as expected for a date field.

You have to be a member [membership is free] of the UtterAccess forum to download the samples from their code archives section of the forum.
 
Last edited:
Christine,

I'll download Allen's stuff and look at it. I'm certain we can get it working.
 
Dazed, Yup, I've looked at Utter Access but the samples didn't work for me.

RG, if you could indeed have a look-see I'll be very grateful. My programming skills just aren't up to the task - I'm much better at learning by example!
 
Christine,

What do you have in the click event of your Dates? Just looking at Allen's documentation makes me believe you almost have it.

I would think something like:

Me.DateBox = CalendarFor(Me.DateBox, "Select a date")

...would work but I'll check it.
 
RG, here's what I've got:
Code:
ActivateCalendarForm "CompletionDate"
Here's the code in frmCalendar:

Code:
Option Compare Database
Dim arArgs() As String

Private Sub UpdateCaller(ByVal DateIn As Date)
On Error GoTo Err_UpdateCaller

Dim fFrm As Form
Dim cCtrl As Control
Dim arFormInfo() As String

arFormInfo = Split(arArgs(0), "*")

  For Each fFrm In Forms
    If fFrm.Name = arFormInfo(1) Then
      If LCase(arFormInfo(0)) = "subform" Then
        Set cCtrl = fFrm.ActiveControl.Form.Controls(arArgs(1))
        cCtrl.Value = DateOpened
      Else
        Set cCtrl = fFrm.Controls(arArgs(1))
        cCtrl.Value = DateIn
      End If
      Exit For
    End If
  Next fFrm
  
Exit_UpdateCaller:
     Exit Sub
     
Err_UpdateCaller:
     MsgBox "If this routine failed it may be because you do not have MSCal.OCX Version 10 installed and/or its" & _
                  "location is not as expected in C:\Program Files\Microsoft Office\Office 10. Please contact the CAR" & _
                  "System Administrator for assistance.", vbCritical, Error
    Resume Exit_UpdateCaller

End Sub


Private Sub Form_Load()
On Error GoTo Err_Form_Load

  If Me.OpenArgs = "" Or IsNull(Me.OpenArgs) = True Then
    MsgBox "This Calendar Form is not designed to be Opened" & vbCrLf & _
           "EXCEPT when Called from an Event in another Form." & vbCrLf & _
           "It will Display, but no further Code will execute...", vbOKOnly + vbInformation, "Improper Use of Calendar"
    Exit Sub
  End If
  
  'Me.OpenArgs contains Whether the form is Main or SubForm, and the name of the TextBox to be updated from the Calendar selection.
  
  arArgs = Split(Me.OpenArgs, "|")
  If Me.OpenArgs <> "" Then
      arArgs = Split(Me.OpenArgs, "|")
    With Me.cal1
      .Month = Month(Date)
      .Day = Day(Date)
      .Year = Year(Date)
    End With
  End If
  
Exit_Form_Load:
     Exit Sub
     
Err_Form_Load:
     MsgBox "If this routine failed it may be because you do not have MSCal.OCX Version 10 installed and/or its" & _
                  "location is not as expected in C:\Program Files\Microsoft Office\Office 10. Please contact the CAR" & _
                  "System Administrator for assistance.", vbCritical, Error
    Resume Exit_Form_Load
    
End Sub

Private Sub cal1_Click()
On Error GoTo Err_cal1_Click

  UpdateCaller cal1.Value
  DoCmd.Close acForm, Me.Name, acSaveNo

Exit_cal1_Click:
    Exit Sub

Err_cal1_Click:
     MsgBox "Please see Christine for assistance.", vbCritical, Error
    Resume Exit_cal1_Click

End Sub

Then, here's the code in the module called ActivateCalendar:

Code:
Private Sub ActivateCalendarForm(ByVal sCtrl As String)

  Dim sArgs As String
  Dim sFullFormName As String
  If IsSubForm(Me) = True Then
    sFullFormName = "SubForm" & "*" & Me.Parent.Name
  Else
    sFullFormName = "Form" & "*" & Me.Name
  End If
  sArgs = sFullFormName & "|" & sCtrl
  DoCmd.OpenForm "frmCalendar", , , , acFormPropertySettings, acDialog, sArgs
End Sub

Private Function IsSubForm(fForm As Form) As Boolean
On Error GoTo HandleErr
  If IsObject(fForm.Parent) Then
    IsSubForm = True  'The Form Passed is a Subform
  Else
    IsSubForm = False 'The Form Passed is a Mainform
  End If

Exit Function
HandleErr:
IsSubForm = False
End Function

I used to have a comment block giving credit for all this code, but somewhere along the way, I must have deleted it.

Cheers,
Christine
 
Christine,

Don't be mad but here's what I did. I took Allen's code and added this to the click event of the target TextBox.

Code:
Private Sub txtStartDate_Click()
Dim Junk As Variant

Junk = CalendarFor([txtStartDate], "Set the start date")

End Sub
His code now works off of the Click event too.

Now I need to go study your code.
 
Oh dear, RG - Don't look at the code I sent to you -- that's all related to the ActiveX control I'm trying to get rid of because the References are all messed up and everyone says that's why you shouldn't use ActiveX.

Alan's code (which I haven't posted yet - it's on his website) is the stuff I'm having difficulty using because the fields in my table for storing dates are formatted as dates, and Allen's code uses text boxes.

Am I getting you confused yet? Thanks for sticking with me!
Christine
 
We are definately looking at different calendars. How long ago did you download? Something tells me Allen might have made a few changes.
 
Don't let the TextBox stuff throw you. Allen's code is working with TextBoxes (a control on a form) that are bound to Date Fields in a RecordSet. DateFields are displayed on forms with TextBoxes. Are you displaying the dates or did you want to modify the Field in the table directly?
 
I got the code to run the ActiveX control (all the lines of code I sent a few posts ago) perhaps ... um... a year and a half ago. I don't know if it was Alan's or not.

The new code IS Alan's and I just got it last Friday from his website.

I'm sorry if I confused things by posting the ActiveX code. Should I post the code (from Alan's site) that I'm currently needing help with?

Christine
 
RuralGuy said:
Don't let the TextBox stuff throw you. Allen's code is working with TextBoxes (a control on a form) that are bound to Date Fields in a RecordSet. DateFields are displayed on forms with TextBoxes. Are you displaying the dates or did you want to modify the Field in the table directly?

Oh - I didn't know about that! As to your question, um... I want the user to pick a date from the calendar and store it in the table. This type of thing would happen for a variety of fields.
 
Just put the code I posted in the click event of each of your dates. Just change the [ControlName] inside the brackets to the name of the control you are working with. That should work.
 
Thanks, RG. I have to leave now to go to another site (hate to leave in the middle of a this!!! :( , but I'll give your code a go in the morning and let you know how I get on.

Many, many thanks!
Christine
 
RG, Just wanted to say thankyou for your assistance. The reference to the text box for filling in dates threw me, but you were right - it works great as-is. Thanks again.
Christine
 

Users who are viewing this thread

Back
Top Bottom