Subform requery

  • Thread starter Thread starter Hugo Marques via AccessMonster.com
  • Start date Start date
H

Hugo Marques via AccessMonster.com

Hi...

I'm trying to requery a subform by clicking a button in the main form. When
the button is clicked an sql statement is generated as a string and saved
into a global variable. After having the global query in the variable I try
to set the focus on the subform which reads the global variable and sets
the query as the recordSource.

The problem is that the focus doesn't seem to move from the button and the
Subform_GotFocus() code never runs. I tryed to do:

Me.Subform.setfocus
Me.subform.requery

and it doesn't work.

I also tryed to create a textbox in the header of the subform and it worked
- the query runs. I did:

Me.subform.setfocus
Me.subform.textbox.setfocus

and in the textbox code:

Private sub textbox_GotFocus()

Me.recordsource = globalvariable
Me.requery

end sub

The problem is that it gives an error in the line
Me.subform.textbox.setfocus saying that it can't move the focus to the the
control TextBox

Any suggestions?

Thanks....

Hugo
 
The main problem is that you don't have the correct syntax for referring to
the subform from the main form. The proper syntax would be:

Me!Subform1.Form.Requery

Think of it this way: on the main form, the subform is just a control, it's
not really a form. Inside that control happens to be a form. Therefore,
you have to refer to the form that's within the subform control in order to
do anything to the form (not a totally correct explanation from a technical
viewpoint, but hopefully makes it a little easier to understand).

Similarly, to refer to a specific textbox on the subform from the main form,
you would use:

Me!Subform1.Form!Textbox1

To set the focus on that textbox, you would put:

Me!Subform1.Form!Textbox1.SetFocus

The Access Web (http://www.mvps.org/access/) has an excellent writeup
describing how to refer to subforms from the main form and vice versa and
the above examples were shamelessly stolen from that writeup.
 
Back
Top