VBA Syntax

  • Thread starter Thread starter Mike C.
  • Start date Start date
M

Mike C.

Hello.

OK. This should be an easy one :o)

I am working on a database whose code for a control on
form "frmSelectGroup" was
originally "Me.Requery "lstGroups". It used to work fine.

Now I have that form as a subform (actually its the
subform of another subform) and when it runs that line of
code I get a "Wrong number of arguments or invalid
property assignemnt" error. I assume that I have to tell
it that that control is now on a subform. What is the
correct syntax to do that?

"frmMailingsRptMenu" is the parent form
"frmSelLabels" is the subform
"frmSelectGroup" is the sub-subform. The "lstGroups "
control is on this form.

Right now I have it as follows:
Me.Requery Forms!frmMailingsRptMenu!frmSelLabels!
frmSelectGroup!lstGroups

What am I missing?

Thanks in advance.

mc
 
Hi,
This line:
Me.Requery "lstGroups"

would never have worked.
Me.Requery will requery the form where the code is running.
That's what the 'Me' means.
There are no arguments to the Requery method, that's why you're seeing the error.

So, first off, what are you trying to requery? It seems like you're trying to requery a listbox.
How you reference it depends on where your code is running from.
If it's running from the form the control is on, then it's simply:
Me.lstGroups.Requery

If the code is running on the form that is the main form to where the listbox is then,
Me.NameOfSubformCtl.Form!lstGroups.Requery

If the code is in the top level form and the listbox is two levels down then,
Me.NameOfSubformCtl1.Form!NameOfSubformCtl2.Form!lstGroups.Requery

The reason I didn't use the form names you supplied is that the form name is not always
the same as the *subform control name*. Check it out in design view and just substitute the real names.
 
Mike said:
I am working on a database whose code for a control on
form "frmSelectGroup" was
originally "Me.Requery "lstGroups". It used to work fine.

No it didn't! ;-)

A method of an object is written"

object.method arglist

not, as you say someotherobject.method "objectname"

Now I have that form as a subform (actually its the
subform of another subform) and when it runs that line of
code I get a "Wrong number of arguments or invalid
property assignemnt" error. I assume that I have to tell
it that that control is now on a subform. What is the
correct syntax to do that?

"frmMailingsRptMenu" is the parent form
"frmSelLabels" is the subform
"frmSelectGroup" is the sub-subform. The "lstGroups "
control is on this form.

Right now I have it as follows:
Me.Requery Forms!frmMailingsRptMenu!frmSelLabels!
frmSelectGroup!lstGroups


Try this:
Me!frmSelLabels!frmSelectGroup!lstGroups.Requery
 
My mistake. The code was:

DoCmd.Requery "lstgroups"

I actually inherited this database from another developer
and cut/paste the wrong code. However, I will try the
fixes provided.

Thanks for the rapid responses!

mc
 
Back
Top