Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Jul 2002
    Location
    Cedar Falls, Iowa, USA
    Posts
    268
    Thanks
    0
    Thanked 0 Times in 0 Posts

    saving frm name in global variable (A2000)

    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

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: saving frm name in global variable (A2000)

    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.

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: saving frm name in global variable (A2000)

    Don't worry, things like that happen to all of us. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

  4. #4
    3 Star Lounger
    Join Date
    Jul 2002
    Location
    Cedar Falls, Iowa, USA
    Posts
    268
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: saving frm name in global variable (A2000)

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •