Can I set a variable reference to a form that is referenced by a variable?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Jon A (JonA_at_wi.rr.com)
Date: 02/26/05


Date: Sat, 26 Feb 2005 00:36:58 GMT

I have a Public function that is called from a number of
different forms. One of the things this function does is to
open a form whose FormName is passed as a parameter into the
function.

I can open the form that is referenced by that variable
easily enough by using the following DoCmd statement.
However, when I try to use SET as shown below I get runtime
errors saying that the form "strTheForm" cannot be found.

Public Function LoadQualityFactors(varTheReviewID As
Variant, strTheForm As String) As Boolean

DoCmd.OpenForm strTheForm

Set frmTheForm = Forms![strTheForm]

end Function

I find that I can open the referenced form only by including
the actual form name in the brackets such as

Set frmTheForm = Forms![frm_DisplayQualityFactors]

The problem I have is that this function is useful for a
number of different forms that I have built and I don't want
to have to code every form name into the function. I thought
it would be possible to use variable references to point to
the different forms.

Can anyone tell me what the correct syntax is? I have
searched MSDN and cannot find a thing.



Relevant Pages

  • Re: Halt screen startling inexperienced users
    ... >place of the SetValue action in your macro, ... RunCode action (we'll ... >Public Function MakeFormInvisible() ... >> I checked my references in VBA again. ...
    (microsoft.public.access.macros)
  • Re: Comparing Two Identical Tables - Loop Through fields in a Recordset
    ... by putting the new public function in a standard ... but when I run the query Access tells me that there is an ... 'Undefined Function 'NullIfEqual' in the expression' ... ... references in the Visual Basic Editor ... ...
    (comp.databases.ms-access)
  • Re: Loading/using a type library
    ... References, so the compiler doesn't know it's going to be there. ... Public Function CheckLibraryAs Boolean ... Dim obj As Object ...
    (microsoft.public.vb.general.discussion)
  • Re: UDF Question
    ... (remove nothere from email address if mailing direct) ... public function foo ...
    (microsoft.public.excel.programming)