Calendar coding

C

Cherry

Can anybody help me what need to be changed on this code?
I found this code from web and want to modify to fit in
to my database. The main purpose of this code is to make
a simple way for user to input data on text box date
field by simply clicking on a button next to that txtXXXX
to call ActiveX Calendar which is on a form. Therefore,
when you click on the date you want, it will show on that
specific field you want it to be.

This code is working great with on main form and subform,
but what I need is I want to make it also work on my sub
sub form....
Mainform
...suform
....subform <-- it won't work at this level.
The following is the code:

///////insert this code on the button you want to call
Calendar
Private Sub cmdCal6_Click()
ActivateCalendarForm Me, "OffStart"
End Sub


////////Insert this code in MODULE
Public Today As Control, ctldate As Control
Private Sub ActivateCalendarForm(ByRef fForm As Form,
ByRef sCtrl As String)
'*****************************************************
' This Sub "ActivateCalendar" and Function "IsSubForm"
' is the Code that calls the Calendar Form.
' You can put this in any form module where you want to
' call the calendar or put it in a Standard Module and
' make it "Public Sub ActivateCalendarForm(ByRef sCtrl As
String)
' and "Public Function IsSubForm(fForm As Form) As
Boolean"
'*******************************************************
Dim sArgs As String
Dim sFullFormName As String
If IsSubForm(fForm) = True Then
sFullFormName = "SubForm" & "*" & fForm.Parent.Name
Else
sFullFormName = "Form" & "*" & fForm.Name
End If
sArgs = sFullFormName & "|" & sCtrl
DoCmd.OpenForm "frmCalendar1", , , ,
acFormPropertySettings, acDialog, sArgs
End Sub

Private Function IsSubForm(ByRef 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


////Add this code under Calendar form
Private Sub cal1_Click()
UpdateCaller cal1.Value
DoCmd.Close acForm, Me.Name, acSaveNo
End Sub

Private Sub Form_Activate()
Form_Resize
End Sub

Private Sub Form_Load()
Form_Resize
'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
End Sub

Private Sub Form_Resize()
With Me
.InsideHeight = 3600
.InsideWidth = 3600
.Detail.Height = 3600
End With
With cal1
.Top = 0
.Left = 0
.Height = 3600
.Width = 3600
End With
End Sub

Private Sub UpdateCaller(ByVal DateIn As Date)
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)) = "" Then
Set cCtrl = fFrm.ActiveControl.Form.Controls
(arArgs(1))
cCtrl.Value = DateIn
Else
Set cCtrl = fFrm.Controls(arArgs(1))
cCtrl.Value = DateIn
End If
Exit For
End If
Next fFrm
End Sub

Thank you in advance,
Cherry
 
S

Stephen Lebans

You did not get the posted code from my site.

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
M

MikeB

Cherry said:
Can anybody help me what need to be changed on this code?
I found this code from web and want to modify to fit in
to my database. The main purpose of this code is to make
a simple way for user to input data on text box date
field by simply clicking on a button next to that txtXXXX
to call ActiveX Calendar which is on a form. Therefore,
when you click on the date you want, it will show on that
specific field you want it to be.

This code is working great with on main form and subform,
but what I need is I want to make it also work on my sub
sub form....
Mainform
...suform
....subform <-- it won't work at this level.

I will come up with a fix for this at any level.... Stay tuned.
 
M

MikeB

Cherry,
I have provided a fix for this and an enhancement in the bargain. I will do a write-up and post the
corrected code sometime later today. The calling convention remains unchanged, except the name of the
Control isn't passed as a string, the Control is passed ByRef, so just remove the Quotes from the name of
your control reference in the function call. I added an optional paramater allowing a Seed value to be
passed to specify the starting date of the calendar, otherwise it behaves as it does now by displaying
the current date.

Mike Byerley
 
M

MikeB

Cherry said:
Can anybody help me what need to be changed on this code?
I found this code from web and want to modify to fit in
to my database. The main purpose of this code is to make
a simple way for user to input data on text box date
field by simply clicking on a button next to that txtXXXX
to call ActiveX Calendar which is on a form. Therefore,
when you click on the date you want, it will show on that
specific field you want it to be.

This code is working great with on main form and subform,
but what I need is I want to make it also work on my sub
sub form....
Mainform
...suform
....subform <-- it won't work at this level.

Fixed..Replace the Calendar Form and the Bas Module and remove the quotes from the Name of the Control
passed in the function argument. Read the Syntax and Info button from the test form for notes on
changes...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top