pass ctl info thru openargs

  • Thread starter Thread starter john
  • Start date Start date
J

john

I have a generic form that I use to edit the list of combo & list boxes. On
the close event of it I want to re-query the calling list or combo box. I
cannot open it as an acDialog form and just have the re-query in the calling
code, because it needs to run code after the form is called to set certain
properties.

I am trying to send explicit control info thru OpenArgs such as the
following, which is then to be used in the close event of the generic form.
But I get a run time error 424, object required , on the set ctl line.

forms!frmMain!frmAccountingTabs!frmProjectTactical!ListPercent

Private Sub Form_Close()
Dim ctl As Control
Set ctl = Me.OpenArgs
With ctl
.Requery
End With
End sub
 
AFAIK, you can't pass a control: the OpenArgs property is strictly a string.

If you've got a short list of possible controls, you could use a Select Case
construct. Otherwise, you might have to parse what was passed and go about
it that way.

BTW, the sample control name you're showing doesn't actually look valid.
Assuming that you're using a form frmProjectTactical as a subform on form
frmAccountingTabs, you're using frmAccountTabs as a subform on form frmMain,
and you want to requery ListPercent on the subform, your reference would
more likely be

forms!frmMain!frmAccountingTabs.Form!frmProjectTactical.Form!ListPercent

This assumes that the name of the subform container on frmMain that
frmAccountingTabs is in is also named frmAccountTabs. If you dragged
frmAccountingTabs onto frmMain to create the form/subform relationship,
that's likely the case. However, if you dragged the Subform control from the
toolbox onto frmMain and then used the wizard to create the form/subform
relationship, it's more likely going to be something like Child0, so that
your reference would more likely be

forms!frmMain!Child0.Form!Child0.Form!ListPercent
 
Thanks for your input,

I decided to just make a public control as a variable and assign it the
explicit control reference, which worked for me. The called form requeries
the calling control on the close event.
Module
Public ctlName As Control

Private Sub Form_Close()
With ctlName
.Requery
End With
End Sub

As for the syntax of the reference, I have done it that way before, but it
seemed not to make difference in my results and saved some typing. Is there
performance issue in my way if it works? Do you see any problem with me
using a Public control as a Variable to requery with?
 
Using public variables can be a problem when an error occurs, as all public
variables are usually reset, but other than that, there shouldn't be any
problem.

I'm surprised that your reference works, but if it is, don't worry about it.
 
Why not use openargs?

docmd.OpenForm "abc",,,,,,"formname,FieldName"

now, in the form...you go


strForm = split(me.OpenArgs,",")(0)
strField = split(me.OpenArgs,",")(1)


forms(strForm).controls(strField).Requery


So, just assume that open arges is always 2 values...the form name + field
name.....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top