Calendar Controls

D

DubboPete

Hi all,

I have many instances where I use a calendar control, on many different
forms within a database.

Up till now, I have created a new form for each instance where a calendar
control is needed (Cal1, Cal2, Cal3, und so weiter), and I was wondering if
there is a way of setting just _one_ calendar control to respond and set a
value for two different fields on two different forms, on separate calls of
the calendar?

Example of what I do at the moment:

' For Form 1 where departure date is selected by calendar
' and using the Onclick event of the calendar control

Forms!Departure![depdate].value = me.calendar1.value ' calendar1 is
located on form 'Cal1'

' For Form 2 where consigned date is selected by calendar
' and using the Onclick event of the calendar control

Forms!Despatch![condate].value = me.calendar2.value ' calendar2 is
located on form 'Cal2'

It all works fine, but creates many overheads by creating many Calxx forms!

I suppose I mean that if a calendar control is CALLED from a form's command
button, the calendar control would be able to differentiate which form's
command button called it, and place the correct value in the necessary field
in the calling form. That's where I am hitting the wall of knowledge!!!

any help greatly appreciated!

DubboPete
 
N

Nikos Yannacopoulos

Pete,

Suppose you have just one calendar form; wherever you are calling it
from, call it like:

DoCmd.OpenForm frmCalendar,,,,,,Me.Name & ";" & Me.ActiveControl.Name
(if the code is in an event of the control to be populated)

or
DoCmd.OpenForm frmCalendar,,,,,,Me.Name & ";" & "ControlName"
(if the code is in an event of another control, like a command button)

where I have assumed the calendar to be on form frmCalendar. This uses
the OpenArgs argument of the OpenForm command to pass on the name of the
original form and the name of the control to be populated, separated by
a semicolon (;).

Now, in the calendar's click event:

sep = InStr(1, OpenArgs, ";")
frm = Left(OpenArgs, sep-1)
ctl = Right(OpenArgs, Len(OpenArgs) - sep)
Forms(frm).Controls(ctl) = Me.calendar1

This piece of code identifies the position of the separating semicolon
in the string, so it can read the name of the form and the control into
frm and ctl respectively, and then use them to reference the control on
the form (I have assumed the calendar control to be named calendar1).
Note: you don't need to reference a control's Value property, it's
referenced by default if no other property is specified.

HTH,
Nikos
 
D

DubboPete

Nicos,

that code looks frantastic, and just the thing I need...
I will try it out over the weekend, and let y'all know...

many thanks

Pete

Nikos Yannacopoulos said:
Pete,

Suppose you have just one calendar form; wherever you are calling it from,
call it like:

DoCmd.OpenForm frmCalendar,,,,,,Me.Name & ";" & Me.ActiveControl.Name
(if the code is in an event of the control to be populated)

or
DoCmd.OpenForm frmCalendar,,,,,,Me.Name & ";" & "ControlName"
(if the code is in an event of another control, like a command button)

where I have assumed the calendar to be on form frmCalendar. This uses the
OpenArgs argument of the OpenForm command to pass on the name of the
original form and the name of the control to be populated, separated by a
semicolon (;).

Now, in the calendar's click event:

sep = InStr(1, OpenArgs, ";")
frm = Left(OpenArgs, sep-1)
ctl = Right(OpenArgs, Len(OpenArgs) - sep)
Forms(frm).Controls(ctl) = Me.calendar1

This piece of code identifies the position of the separating semicolon in
the string, so it can read the name of the form and the control into frm
and ctl respectively, and then use them to reference the control on the
form (I have assumed the calendar control to be named calendar1).
Note: you don't need to reference a control's Value property, it's
referenced by default if no other property is specified.

HTH,
Nikos
Hi all,

I have many instances where I use a calendar control, on many different
forms within a database.

Up till now, I have created a new form for each instance where a calendar
control is needed (Cal1, Cal2, Cal3, und so weiter), and I was wondering
if there is a way of setting just _one_ calendar control to respond and
set a value for two different fields on two different forms, on separate
calls of the calendar?

Example of what I do at the moment:

' For Form 1 where departure date is selected by calendar
' and using the Onclick event of the calendar control

Forms!Departure![depdate].value = me.calendar1.value ' calendar1 is
located on form 'Cal1'

' For Form 2 where consigned date is selected by calendar
' and using the Onclick event of the calendar control

Forms!Despatch![condate].value = me.calendar2.value ' calendar2 is
located on form 'Cal2'

It all works fine, but creates many overheads by creating many Calxx
forms!

I suppose I mean that if a calendar control is CALLED from a form's
command button, the calendar control would be able to differentiate which
form's command button called it, and place the correct value in the
necessary field in the calling form. That's where I am hitting the wall
of knowledge!!!

any help greatly appreciated!

DubboPete
 

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