Accessing fields from form

A

andrew3254

Hi, I have a form which has many subforms, one for each month of the year and
a bit of code which sets the focus to the current month and changes the
background colour.

How do i go about accessing a field called month on that form?

Here is the code i have so far:
stran = "Month" & Month(Now)
Set ctl = Forms![Frm_View
Detailed].Form.Controls("sub").Form.Controls(stran) '.ActiveControl
ctl.SetFocus
 
D

Dale Fye

Andrew,

Not sure why you need a separate subform for each month of the year.
Normally, you would design the subform so that it filters it's data based on
a value in your main form (master/child relationship). Alternately, you
could set up the recordsource of the subform so that it actually filters the
recordset based on a value in the main form.

However, if you actually have 12 subforms, then you need to refer to the
subform by its appropriate control name. I would think that this might look
like:

Set ctl = Forms![Frm_ViewDetailed].Controls("sub" & stran).Form

But what I suspect you really want to do is actually set the control to a
field or control within that subform, something like, which you should be
able to do something like:

Forms![Frm_ViewDetailed].Controls("sub" &
stran).Form.txt_SomeControl.setfocus

HTH
Dale
 
A

andrew3254

When I started working for the company it was designed that way and worked,
just seems to be calling a query when they dont want it too. I know what
data I need in the side condition just cant seem to get it.

They have a way of accessing the appropriate form to change the back colour,
just couldnt find out how to access an object from that form rather that
access the properties.

Ill give that a go, cheers.
--
Thank you




Dale Fye said:
Andrew,

Not sure why you need a separate subform for each month of the year.
Normally, you would design the subform so that it filters it's data based on
a value in your main form (master/child relationship). Alternately, you
could set up the recordsource of the subform so that it actually filters the
recordset based on a value in the main form.

However, if you actually have 12 subforms, then you need to refer to the
subform by its appropriate control name. I would think that this might look
like:

Set ctl = Forms![Frm_ViewDetailed].Controls("sub" & stran).Form

But what I suspect you really want to do is actually set the control to a
field or control within that subform, something like, which you should be
able to do something like:

Forms![Frm_ViewDetailed].Controls("sub" &
stran).Form.txt_SomeControl.setfocus

HTH
Dale

--
Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.



andrew3254 said:
Hi, I have a form which has many subforms, one for each month of the year and
a bit of code which sets the focus to the current month and changes the
background colour.

How do i go about accessing a field called month on that form?

Here is the code i have so far:
stran = "Month" & Month(Now)
Set ctl = Forms![Frm_View
Detailed].Form.Controls("sub").Form.Controls(stran) '.ActiveControl
ctl.SetFocus
 

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