• saving frm name in global variable (A2000)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » saving frm name in global variable (A2000)

    Author
    Topic
    #406318

    I have a subform with a combo box with a not in list event that calls a data entry form. Closing the data entry form needs to include requerying the subform’s cboBox. The combo box could be on one of two subforms. I’m trying to save the name of the subform in a global variable called gstrSubformName and then refer to it in the Close event code but it’s not happening.

    The basFormName includes:
    Option Compare Database
    Option Explicit
    Public gstrSubformName As String

    The subform’s Not In List code includes the following:
    Dim gstrSubformName As String
    gstrSubformName = Me.Name

    The cmdClose on the data entry form is as follows:
    Private Sub cmdClose_Click()
    Dim frm As Form
    Dim strFormName As String
    Dim gstrSubformName As String
    Dim lngCSZID As Integer

    Set frm = Forms(gstrSubformName)

    lngCSZID = Me![txtAddrHmID]

    ‘blnCanClose = True
    DoCmd.Close acForm, Me.Name, acSaveNo
    frm.Requery
    frm![cboCSZID].Requery
    frm.[cboCSZID] = lngCSZID

    End Sub

    I’m getting an error that it can’t find the form and the variable is an empty string. Where am I messing up? Can you tell from what I’ve posted?

    E

    Viewing 0 reply threads
    Author
    Replies
    • #841677

      Since you have already declared gstrSubformName as a public variable in basFormName, you should NOT declare it again in the various procedures:

      Private Sub cmdClose_Click()
      Dim gstrSubformName As String

      Within cmdClose_Click, gstrSubformName will be a local variable that has no link with the global variable of the same name. So the global variable is never assigned a value.

      Remove all the “local” declarations of gstrSubformName, and keep only the one in basFormName.

      • #841696

        don’t mind asking questions when I’m learning something new…but i hate it when I look at the obvious and can’t see it. Sorry to have taken your time.

        Should I be requerying the subform or the subform control on the main form?

        E

        • #841698

          Don’t worry, things like that happen to all of us. smile

        • #841699

          Don’t worry, things like that happen to all of us. smile

      • #841697

        don’t mind asking questions when I’m learning something new…but i hate it when I look at the obvious and can’t see it. Sorry to have taken your time.

        Should I be requerying the subform or the subform control on the main form?

        E

    Viewing 0 reply threads
    Reply To: saving frm name in global variable (A2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: