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

    determine main form's name (a2003)

    I've got a subform that has a command button opening a popup form. The subform is on two different forms. The code on the close command of the popup form needs to be specific to which form the subform is located on. How can I set up an If...Then referring to the main form's name?

    Any help appreciated,

    E

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

    Re: determine main form's name (a2003)

    From the subform, the main form is its Parent, and the name of the main form is Me.Parent.Name. You will have to pass this to the popup form. One way to do this is the OpenArgs argument of DoCmd.OpenForm, for example

    DoCmd.OpenForm "frmPopup", , , , , acDialog, Me.Parent.Name

    or equivalently

    DoCmd.OpenForm FormName:="frmPopup", WindowMode:=acDialog, OpenArgs:=Me.Parent.Name

    You can use OpenArgs in the code behind the popup form:

    If Not IsNull(Me.OpenArgs) Then
    ' code goes here
    End If

    An alternative is to declare a public variable in a standard module:

    Public strFormName As String

    and set it before opening the popup form:

    strFormName = Me.Parent.Name
    DoCmd.OpenForm "frmPopup"

    You can then use it in the code behind the popup form:

    If Not strFormName = "" Then
    ' Code goes here
    End If

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

    Re: determine main form's name (a2003)

    Perfect. You just opened new vistas.

    E

  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: determine main form's name (a2003)

    Ooops, spoke to soon. I adopted the second approach and created the global variable gstrFormName. No problems with capturing the main form information. However, the code I'm using uses the collection. So, plugging gstrFormName in in place of frmEnterOrg doesn't work. How can I requery the fsubAddress on form stored in the variable gstrFormName? Thanks for your continued help!

    E.

    Private Sub Form_Close()
    Dim frm As Form

    Set frm = Forms!frmEnterOrg!fsubAddrMlg.Form
    'Set frm = gstrFormName.fsubAddr

    frm.Requery
    frm.RecordsetClone.FindFirst "[lngcszID] = " & frm![cboCSZID]
    frm.Bookmark = frm.RecordsetClone.Bookmark

    End Sub

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

    Re: determine main form's name (a2003)

    You originally asked for the name of the form, and that's what my reply gave you. Now you want to use the form object. That is not the same.

    Keeping gstrFormName you can refer to the form object as Forms(gstrFormName):

    Set frm = Forms(gstrFormName)!fSubAddr.Form

    Another way would be to use a global variable of type Form:

    Public gfrmForm As Form

    Set it like this (must use Set since we're now dealing with an object):

    Set gfrmForm = Me.Parent

    and use like this:

    Set frm = gfrmForm!fSubAddr.Form

Posting Permissions

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