How to access a control from subform

W

WANNABE

Hi. I am trying to use a calendar to set the date on a subform, but the
best place to pu t the calendar object is of course on the main form. This
is what I have been working with>>

Private Sub EndDate_click()
Set actvdatefld = [EndDate]
Forms.Parent.Calendar.Visible = True
Forms.Parent.Calendar.SetFocus
Forms.Parent.Calendar.Value = IIf(IsNull(actvdatefld), Date,
actvdatefld.Value)
End Sub

Private Sub Calendar_Click()
actvdatefld.Value = Forms.Parent.Calendar.Value
cbo_Vendor.SetFocus
Forms.Parent.Calendar.Visible = False
End Sub

AND THIS IS ALL I HAVE IN THE DECLARATIONS
Option Compare Database

I just occured to me that maybe I need something more there, but Again I
feel clue less?
Thanks for any help!!
 
A

Allen Browne

If you have a control name Ctl1 on the main form, from the subform you would
refer to it as:
Me.Parent.[Ctl1]
Replace Ctl1 with the name of your actual control, but leave the other parts
unchanged.

If you are interested in using a simple little Access form as a popup
calendar, see:
http://allenbrowne.com/ser-51.html
You can show your subform in Continuous View (rather than Datasheet view),
and put the command button into the Detail section so it is next to the date
field(i.e. it repeats on each row), or even in the Form Header section (so
it applies to the current row.)

It is always a good idea to include this line in the general declarations:
Option Explicit
 
W

WANNABE

Thanks Allen I have downloaded that popup, and will try that, but first I
want to be able to make this work. It's all a learning process.
I've made the changes as suggested and that solved the old problem, but now
there are a few others.
There are 2 forms, and of course 2 modules. [Startdate] is in the subform.
DECLARATIONS ON BOTH MODULES ARE NOW SET AS FOLLOWS
Option Compare Database
Option Explicit
Dim actvdatefld As Object DID THIS THINKING IT MAY ALLOW ME TO PASS THE
VARIABLE BETWEEN MODULES. I'm sure I don't have this right either, please
tell me how it should be?

Private Sub StartDate_click()
actvdatefld = [StartDate] <THIS CAUSES AN "OBJECT VARIABLE OR WITH
BLOCK VARIABLE NOT SET" ERROR
Me.Parent.Calendar.Visible = True
Me.Parent.Calendar.SetFocus
Me.Parent.Calendar.Value = IIf(IsNull(actvdatefld), Date,
actvdatefld.Value)
End Sub

Realizing that the calendar control is on the parent form I moved that code
to the parent module
Private Sub Calendar_Click()
' Set Date to the selected date and hide the calendar.
actvdatefld.Value = Calendar.Value
' Notes.SetFocus THIS FIELD IS ON THE SUBFORM, NOT SURE HOW TO
ADDRESS IT FROM THE MAIN FORM?
Calendar.Visible = False
End Sub
With that information can you tell me all the things I'm doing wrong??
Thank You!

Allen Browne said:
If you have a control name Ctl1 on the main form, from the subform you
would refer to it as:
Me.Parent.[Ctl1]
Replace Ctl1 with the name of your actual control, but leave the other
parts unchanged.

If you are interested in using a simple little Access form as a popup
calendar, see:
http://allenbrowne.com/ser-51.html
You can show your subform in Continuous View (rather than Datasheet view),
and put the command button into the Detail section so it is next to the
date field(i.e. it repeats on each row), or even in the Form Header
section (so it applies to the current row.)

It is always a good idea to include this line in the general declarations:
Option Explicit

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

WANNABE said:
Hi. I am trying to use a calendar to set the date on a subform, but the
best place to pu t the calendar object is of course on the main form.
This is what I have been working with>>

Private Sub EndDate_click()
Set actvdatefld = [EndDate]
Forms.Parent.Calendar.Visible = True
Forms.Parent.Calendar.SetFocus
Forms.Parent.Calendar.Value = IIf(IsNull(actvdatefld), Date,
actvdatefld.Value)
End Sub

Private Sub Calendar_Click()
actvdatefld.Value = Forms.Parent.Calendar.Value
cbo_Vendor.SetFocus
Forms.Parent.Calendar.Visible = False
End Sub

AND THIS IS ALL I HAVE IN THE DECLARATIONS
Option Compare Database

I just occured to me that maybe I need something more there, but Again I
feel clue less?
Thanks for any help!!
 
A

Allen Browne

If you do what to refer to an object, use the Set keyword.
Set actvdatefld = [StartDate]
However, this will still only be available within the form's module, unless
you make it Public and include the full module reference.

For help on how to refer to a control in a subform, see:
Referring to Controls on a Subform
at:
http://allenbrowne.com/casu-04.html

You won't need to do any of that with the download example.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

WANNABE said:
Thanks Allen I have downloaded that popup, and will try that, but first I
want to be able to make this work. It's all a learning process.
I've made the changes as suggested and that solved the old problem, but
now there are a few others.
There are 2 forms, and of course 2 modules. [Startdate] is in the subform.
DECLARATIONS ON BOTH MODULES ARE NOW SET AS FOLLOWS
Option Compare Database
Option Explicit
Dim actvdatefld As Object DID THIS THINKING IT MAY ALLOW ME TO PASS THE
VARIABLE BETWEEN MODULES. I'm sure I don't have this right either, please
tell me how it should be?

Private Sub StartDate_click()
actvdatefld = [StartDate] <THIS CAUSES AN "OBJECT VARIABLE OR WITH
BLOCK VARIABLE NOT SET" ERROR
Me.Parent.Calendar.Visible = True
Me.Parent.Calendar.SetFocus
Me.Parent.Calendar.Value = IIf(IsNull(actvdatefld), Date,
actvdatefld.Value)
End Sub

Realizing that the calendar control is on the parent form I moved that
code to the parent module
Private Sub Calendar_Click()
' Set Date to the selected date and hide the calendar.
actvdatefld.Value = Calendar.Value
' Notes.SetFocus THIS FIELD IS ON THE SUBFORM, NOT SURE HOW TO
ADDRESS IT FROM THE MAIN FORM?
Calendar.Visible = False
End Sub
With that information can you tell me all the things I'm doing wrong??
Thank You!

Allen Browne said:
If you have a control name Ctl1 on the main form, from the subform you
would refer to it as:
Me.Parent.[Ctl1]
Replace Ctl1 with the name of your actual control, but leave the other
parts unchanged.

If you are interested in using a simple little Access form as a popup
calendar, see:
http://allenbrowne.com/ser-51.html
You can show your subform in Continuous View (rather than Datasheet
view), and put the command button into the Detail section so it is next
to the date field(i.e. it repeats on each row), or even in the Form
Header section (so it applies to the current row.)

It is always a good idea to include this line in the general
declarations:
Option Explicit

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

WANNABE said:
Hi. I am trying to use a calendar to set the date on a subform, but the
best place to pu t the calendar object is of course on the main form.
This is what I have been working with>>

Private Sub EndDate_click()
Set actvdatefld = [EndDate]
Forms.Parent.Calendar.Visible = True
Forms.Parent.Calendar.SetFocus
Forms.Parent.Calendar.Value = IIf(IsNull(actvdatefld), Date,
actvdatefld.Value)
End Sub

Private Sub Calendar_Click()
actvdatefld.Value = Forms.Parent.Calendar.Value
cbo_Vendor.SetFocus
Forms.Parent.Calendar.Visible = False
End Sub

AND THIS IS ALL I HAVE IN THE DECLARATIONS
Option Compare Database

I just occured to me that maybe I need something more there, but Again I
feel clue less?
Thanks for any help!!
 
W

WANNABE

Sorry, but I just don't follow it all well enough to make this work yet.
When I step through the modules startdate_click closes before calendar click
is started from clicking on the calendar, and thus I see no way of passing a
variable value from one module to another. As I watch the locals window I
see what I think is the full module reference, but even that wont work and I
don't see any expressions or values in the locals window any longer once
startdate_click finishes...
I tried stuff like
set WD.[Form_Tasks subform].StartDate_click.actvdatefld.Value =
Calendar.Value
I know there is a key here of great value that I am missing, please clue me
in..

ALSO Allen, I read your link http://allenbrowne.com/casu-04.html it is very
helpful, but, where you say <"Grades" is the name of the control that holds
the subform> It sounds like you are saying that this is NOT the subform
name, but something else. Can you tell me where to find the name of the
control that holds the subform?
Thank you again..
=================================================
Allen Browne said:
If you do what to refer to an object, use the Set keyword.
Set actvdatefld = [StartDate]
However, this will still only be available within the form's module,
unless you make it Public and include the full module reference.

For help on how to refer to a control in a subform, see:
Referring to Controls on a Subform
at:
http://allenbrowne.com/casu-04.html

You won't need to do any of that with the download example.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

WANNABE said:
Thanks Allen I have downloaded that popup, and will try that, but first I
want to be able to make this work. It's all a learning process.
I've made the changes as suggested and that solved the old problem, but
now there are a few others.
There are 2 forms, and of course 2 modules. [Startdate] is in the
subform.
DECLARATIONS ON BOTH MODULES ARE NOW SET AS FOLLOWS
Option Compare Database
Option Explicit
Dim actvdatefld As Object DID THIS THINKING IT MAY ALLOW ME TO PASS THE
VARIABLE BETWEEN MODULES. I'm sure I don't have this right either,
please tell me how it should be?

Private Sub StartDate_click()
actvdatefld = [StartDate] <THIS CAUSES AN "OBJECT VARIABLE OR WITH
BLOCK VARIABLE NOT SET" ERROR
Me.Parent.Calendar.Visible = True
Me.Parent.Calendar.SetFocus
Me.Parent.Calendar.Value = IIf(IsNull(actvdatefld), Date,
actvdatefld.Value)
End Sub

Realizing that the calendar control is on the parent form I moved that
code to the parent module
Private Sub Calendar_Click()
' Set Date to the selected date and hide the calendar.
actvdatefld.Value = Calendar.Value
' Notes.SetFocus THIS FIELD IS ON THE SUBFORM, NOT SURE HOW TO
ADDRESS IT FROM THE MAIN FORM?
Calendar.Visible = False
End Sub
With that information can you tell me all the things I'm doing wrong??
Thank You!

Allen Browne said:
If you have a control name Ctl1 on the main form, from the subform you
would refer to it as:
Me.Parent.[Ctl1]
Replace Ctl1 with the name of your actual control, but leave the other
parts unchanged.

If you are interested in using a simple little Access form as a popup
calendar, see:
http://allenbrowne.com/ser-51.html
You can show your subform in Continuous View (rather than Datasheet
view), and put the command button into the Detail section so it is next
to the date field(i.e. it repeats on each row), or even in the Form
Header section (so it applies to the current row.)

It is always a good idea to include this line in the general
declarations:
Option Explicit

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

"WANNABE" <breichenbach AT istate DOT com> wrote in message
Hi. I am trying to use a calendar to set the date on a subform, but
the best place to pu t the calendar object is of course on the main
form. This is what I have been working with>>

Private Sub EndDate_click()
Set actvdatefld = [EndDate]
Forms.Parent.Calendar.Visible = True
Forms.Parent.Calendar.SetFocus
Forms.Parent.Calendar.Value = IIf(IsNull(actvdatefld), Date,
actvdatefld.Value)
End Sub

Private Sub Calendar_Click()
actvdatefld.Value = Forms.Parent.Calendar.Value
cbo_Vendor.SetFocus
Forms.Parent.Calendar.Visible = False
End Sub

AND THIS IS ALL I HAVE IN THE DECLARATIONS
Option Compare Database

I just occured to me that maybe I need something more there, but Again
I feel clue less?
Thanks for any help!!
 

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

Similar Threads


Top