Subforms datasheet

A

aarrgghh765

Hello,

I've been trying to understand the example in the following article
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsmart01/html/sa01b1.asp

As far as I can see, something like this should work. But Me does not
appear to contain a frmContainersSubForm object and I can't
understand why

Dim sfrm As SubForm

Set sfrm = Me.frmContainersSubForm
sfrm.Form("DateReady").ColumnHidden = True

Can anyone help please as my noodle is well and truly baked.
 
D

Douglas J Steele

You need to make sure you're trying to reference the correct thing.

On the main form, you have a subform container. That subform container's
name may or may not be the same as the form that's being used as the Control
Source for the subform container.

Make sure you're using the name of the subform container if it's not the
same as the form that's being used as the subform.
 
A

aarrgghh765

Douglas said:
You need to make sure you're trying to reference the correct thing.

On the main form, you have a subform container. That subform container's
name may or may not be the same as the form that's being used as the Control
Source for the subform container.

Make sure you're using the name of the subform container if it's not the
same as the form that's being used as the subform.

Thanks Douglas,

My general understanding of subforms and containers is a little
sketchy, I'm at best an amateur.

Opening the parent form I see the container, right clicking on its
properties shows me that the name is Containers Subform.

Changing my code to:

Dim sfrm As SubForm
Dim ctl As Control
Dim sctl As String

Set sfrm = Me.Containers_Subform

sfrm.Form(0).ColumnHidden = True
'sfrm.Form("ReadyDate").ColumnHidden = True 'Doesn't
work either

Now allows execution without error but doesn't do what I hope, i.e.
setting the ColumnHidden property to True.

Note I also tried this which didn't work either, not suprising
possibly as I'm now stabbing in the dark.

Dim sfrm As SubForm
Dim ctl As Control
Dim ctlcol As Collection
Dim sctl As String

Set sfrm = Me.Containers_Subform

For Each ctl In sfrm.Form.Controls
If ctl.Name = "ReadyDate" Then
MsgBox ("found")
End If
Next
 
D

Douglas J Steele

If the name of the container is Containers Subform (with a space), try:

Set sfrm = Me![Containers Subform]

or


Set sfrm = Me.Controls("Containers Subform")
 
A

aarrgghh765

Douglas, thank you very much for your help thus far. I'm afraid I'm
still having trouble. The code as it stands is

Dim sfrm As SubForm
Dim ctl As Control
Dim ctlcol As Collection
Dim sctl As String

'Set sfrm = Me![Containers Subform]
Set sfrm = Me.Controls("Containers Subform")

For Each ctl In sfrm.Form.Controls
If ctl.Name = "ReadyDate" Then
MsgBox ("found")
End If
Next

As you can see I've attempted both changes.and I can't get either to
work. Do you think the way I'm handling referencing the collection is
correct I just don't know what I'm doing wrong here.

I will be eternally grateful if someone could help with this.
 
D

Douglas J Steele

I just double-checked that the code should work, and it does.

What happens if you use:

For Each ctl In sfrm.Form.Controls
Debug.Print ctl.Name
Next

Do you see all of the controls that you expect on the subform?
 
A

aarrgghh765

Doug, you are truly a star. I can't thank you enough for sticking
with this for me and helping me out.

I can't buy you a beer mate, but I'll salute you the next time I have
one.

Using the debug.print ctl.name I could see that there was a typo in the
name of the control that I hadn't previously spotted, you've also
taught me a bit about objects.

The code now works perfectly.
 

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