Referencing a subform

  • Thread starter Thread starter Natalie
  • Start date Start date
N

Natalie

Hi - I have a subform with a combo box in it - I need to
be able to add values to this box if they aren't in the
list - i use the OnNotinList property to open my list of
supporters and add a new name - but then I am trying to
set the OnClose property of this form (the one with the
names in) so that it requerys the control on my subform
(called supporter) and the new value appears in the list -
I have used a similar code to the one below in another
place on my main form and it has worked fine but it says
it can't find the subform I am referrencing - can anyone
help?

Dim supporters As Control
Set supporters = Forms!Supportheadersubform!Supporter

supporters.Requery
supporters.SetFocus


Thanks!
 
To refer to a subform, the syntax is

Forms!frmNameOfMainForm!NameOfSubformControl.Form!NameOfControlOnSubform

The NameOfSubformControl is the name of the control on the main form that holds the
subform, not the name of the subform itself. To get this name, open the main form in
design mode, open the Properties sheet, click on the subform ONE time. The Properties
sheet should show the name of the subform control. If you click a 2nd time, you will be in
the subform itself and the Properties sheet will show the name of the form, not the
control holding it.

Now, for adding items to the combo box.

When you pop-up the form for adding the new data in the combo box's NotInList event, open
the pop-up with the acDialog Window Mode argument. This will pause the code until you
close or hide the pop-up form. When the code resumes you need a line that says

Response = acDataErrAdded

This will tell the combo box that new data has been added and the combo box will requery
all by itself.
 
That works brilliantly - thanks!
Is there anyway I can set the focus on the pop up form to
automatically go to a new record? This is my code so far!!

Private Sub Supporter_NotInList(NewData As String,
Response As Integer)

Supporter = Null

DoCmd.OpenForm "Supportersfrm", acNormal, , , , acDialog

Response = acDataErrAdded

End Sub

Thanks very much!


-----Original Message-----
To refer to a subform, the syntax is

Forms!frmNameOfMainForm!NameOfSubformControl.Form! NameOfControlOnSubform

The NameOfSubformControl is the name of the control on the main form that holds the
subform, not the name of the subform itself. To get this name, open the main form in
design mode, open the Properties sheet, click on the
subform ONE time. The Properties
sheet should show the name of the subform control. If you
click a 2nd time, you will be in
the subform itself and the Properties sheet will show the name of the form, not the
control holding it.

Now, for adding items to the combo box.

When you pop-up the form for adding the new data in the
combo box's NotInList event, open
 
You can make it a Data Entry form by changing its Properties in design mode or by adding
the DataMode parameter to the OpenForm call. This will make the form accept new records
only.

DoCmd.OpenForm "Supportersfrm", acNormal, , , acFormAdd, acDialog

If you don't want to restrict it to this, you can add

DoCmd.GotoRecord acForm, Me.Name, acNewRec

to the Load event of the pop-up. This will take you to the new record, but the others will
be there for editing.
 
Back
Top