Requery on a subform

jminelli

New member
Local time
Today, 05:17
Joined
Jul 30, 2008
Messages
3
Dear Members,
I’m experiencing big troubles with a requery command.
Here it is a simplification of my issue: I’ve built a general form containing the name of the persona, the category of his expertise (for instance economics, human resources…etc). I want to link each category to different options (areas), like, economics= finance, macroeconomics and so on…I want the combo box of areas depend on the category choice. I know how to link those two combo boxes in the same form, but not in case of a subform in the general one. So, what is the command to requery the category combo box, after update event, to the subform?

Many thanks,
J.M.
 
Hey rainman, thank you, but I don't understand wich one to use...could you help me more? I'm sorry I don't get, but I'm at myfirt steps in access.
 
Ok...

I tried the link you suggested. I still can't get it to work.

Main form = frmMainData
Sub form = frmSubComponent
control on frmSubComponent I would like to requery = cboLocation

Form I close that activates this requery is frmAddLocation

I have tried the following:

Code:
Private Sub Form_Close()
Me!frmSubComponent.Form!cboLocation.Requery
End Sub

or

Private Sub Form_Close()
Me!frmMainData.Form!frmSubComponent.Form!cboLocation.Requery
End Sub

or
Private Sub Form_Close()
[Forms]![frmMainData].[Form]![frmSubComponent].[cboLocation].Requery
End Sub

among others. I can't seem to get it to work.
 
Howzit

When you put a subform on your form, access will ask you to specify a name to give the subform. By default this name is the name of the subform itself. However this may have been changed when inserting the subform, or later.

E.g I inserted a subform (frmCalendar) onto a form, and gave it a name called Jack.

To reference this a control on this form i would use the following:

Code:
me.[b]Jack[/b].Form!mycontrol
not
Code:
me.[b]frmCalendar[/b].Form!mycontrol

Check the name of the control holding the subform to see if it is what you expect it to be.

Also note your code below has the code executing on Form_Close
 
Kiwiman

That is correct re: code executing on Form_Close. I have another form that opens so I can add additional locations as they arise. When it closes I would like it to requery the box it is associated with. I am trying your suggestion now and I will let you know.

Thanks


Also. I looked at the properties of the subform and it is also tabbed: TabCtl16 would this make a difference?
 
you can ignore tabctrls when it comes to referencing controls even though it is a control in itself. Just treat it like it is not there. Just the container holding the form itself is the one.
 
Ok.. I did the following code:

Code:
Private Sub Form_Close()
Me!frmSubComponent.Form!cboLocation.Requery
End Sub

I am still getting the following error:
Run-time error 2465
microsoft office access can't find the field 'frmSubcompnent' referred ito in your expression.
 
Howzit

It looks like teh right syntax

in vb editor, after your Private Sub

type me.
once you type the . a list of options will come up does the "frmSubComponent" show up? - this should be the name of the container that holds thh subform. If not you want to find the name of the container.

An example I just created below and definitely works is

Code:
Me.subSubform.Form!Model.Requery
where subSubform is the subform container that holds subform "frmModel", and "Model" is combo box.
 
Ah... no the subform was not showing up. Let me check something.
 
It is showing the following under caption and under source object: frmSubComponent

However this subform is on a tabbed interface. I don't know if that will make a difference or not again, but I thought I would put it in there.
 
in design view of your main form click on the subform container, view the properties. Go to name - that is the value you want
 
Howzit

Sorry, the name is on the "Other" tab
 
Here you go:

frmSubComponent

I also attached a pic just to make sure we are talking about the same thing.
 

Attachments

  • screen_1.jpg
    screen_1.jpg
    78.5 KB · Views: 161
Howzit

That looks like the right value, can't work out why yours does not work.

I have loaded a small database. If you DL it open form frmMain and click on the command4 button. THis requeries the combo, and puts the value of the combo in the text box on the main form.

Check the code below it
 

Attachments

Howzit

had a closer look at your question. I think the problem is that the combobox you are trying to requery from (frmAddLocation) is in another form entirely, not a subform of frmaddlocation. As long as the form is open try

Code:
Forms![frmMainData].[Form]![frmSubComponent].Form![cboLocation].Requery

Sorreee...
 
Kiwiman..

That did the trick. Thank you very much. No need to be sorry! Thank you! I was so close!
 

Users who are viewing this thread

Back
Top Bottom