Referring to a subform in visual basic

wjoc1

Registered User.
Local time
Today, 16:45
Joined
Jul 25, 2002
Messages
117
Hi,

I need to refer to a subform to check if the contents of it have been changed. Even though I use the exact same syntax to check the main form(this works fine) it doesn't seem to work for the subrform.
For example say, the main forms name was:

Polling 20kV-Add a Record

and the name of the subform in it's properties box was:

Pole Attributes

I have used the following code:

If Forms![Polling 20kV-Add a Record]![Pole Attributes].Form.Dirty Then
Call Conf
Else
DoCmd.Close
End If

Conf is just a function that displays a message box.

As I said the exact same syntax seems to work fine for the main form. Can someone please tell me what I am doing wrong and how to call the subform properly?

Thanks,

Liam
 
Is [Pole Attributes] the name of the subform control (in which case it should work) or the name of the form displayed by the subform control (in which case it probably won't work)?
 
It's the name of the control and not the name of the form. I just don't get it! Must be doing something else wrong :-)

Thanks for your help

Liam
 
Wjoc1

This is an example;

'this references the main form
Forms!YourMainFormName

You may have to get the focus away from the subform, before you can reference it.

DoCmd.GotoControl Me!SomeControlOnYourMainForm

'this references the subform
Forms!YourMainFormName![YourSubFormName].Form

Hope that helps
Tom
 
Use the before update event of the subform control
Private Sub Address_BeforeUpdate(Cancel As Integer)
If Me.NewRecord = False And Me.Dirty Then
Call Conf
End If
End Sub
 

Users who are viewing this thread

Back
Top Bottom