Search code examples
vbams-accessparametersglobal-variablesms-access-2010

Storing Multiple Parameters in Global Constant


I am using an Access 2010 database and I cannot figure out how to store multiple parameters for a function call in a single constant string.

For example, let's say I want to open a form with the following:

DoCmd.OpenForm "someformname",acNormal,,"ID=50",acFormEdit, acWindowNormal,"OPENARGS"

Can I store all that in a global constant such as

Public Const C_FORMOPENEDIT as String

and then open the form like this?

DoCmd.OpenForm C_FORMOPENEDIT

It does not seem to work in this way. How can I get VBA to recognize that this is a series of parameters separated by commas? Or is this not possible?

Note: I have attempted already to call it by the parameter name such as FormName := and I have also already verified that any quotes in the string, where needed, are passed through. (like """)


Solution

  • What you want to do isn't possible. Your constant will be evaluated as if it is the name of the form. Since it is constant and not dynamic, I'd suggest to create separate procedures, such as

    Public Sub FormOpenEdit(sFormName As String)
    
        DoCmd.OpenForm sFormName, acNormal, , "ID=50", acFormEdit, acWindowNormal, "OPENARGS"
    
    End Sub
    
    Public Sub FormOpenAdd(sFormName As String)
    
        DoCmd.OpenForm sFormName, acNormal, , "ID=50", acFormAdd, acWindowNormal, "OPENARGS"
    
    End Sub
    

    Alternatively you could build a Enum to select the mode, so you can use just one sub