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
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