Results 1 to 5 of 5
  1. #1
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Subform Not Open (A2k SR1)

    In a subform, I have placed a combobox that allows the user to select a record. The after update event of the combo box then triggers the following code to load the record and associated data. (This is being used as a quick search feature instead of having to go through the records one after another to find the current record.) There are many records.

    Dim x As Integer

    x = Me.GetAIN.Value 'Get record to view from combobox named GetAIN
    DoCmd.GoToRecord acDataForm, "ActionItemMaster Subform", acGoTo, x

    However, when I execute this, I get the error message,

    Runtime Error 2489, The Object "ActionItemMaster Subform" isnt open.

    How do I open the subform or make it current so this will work?

    NOTE: If I eliminate the parent form, this feature works without issue.


    -Other issues to contend with.
    1. There is a main form, subform, and subsubform. I am working with the subform. All three contain different datasets, however, all are related.
    Regards,

    Gary
    (It's been a while!)

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

    Re: Subform Not Open (A2k SR1)

    You should move to the subform first using SetFocus or GotoControl, and then use GotoRecord without specifying the form:

    DoCmd.GotoControl "ActionMaster Subform"
    DoCmd.GotoRecord , , acGoto, x

    Note: "ActionMaster Subform" must be the name of the subform control on the main form - this is not necessarily the same as the name of the subform in the database window.

  3. #3
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Subform Not Open (A2k SR1)

    Thanks Hans.

    I originally set the focus to the subform when the original main form opened, but that created all kinds of problems with other code occurring on the main form on the on open event.

    I guess that what is confusing me is that when I change a value in the combobox on the subform, wouldn't, by default, the focus be set to the subform? Perhaps it is time for me to read up on this.

    Also - How would you go about finding the name of all of the subform controls on the main form?

    Thanks
    Regards,

    Gary
    (It's been a while!)

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

    Re: Subform Not Open (A2k SR1)

    Hi Gary,

    I didn't read your original question carefully enough. Since you call the code in the AfterUpdate event of a combo box on the subform, you don't need to use GoToControl, and you don't need to specify an object for GoToRecord either. Just <font face="Georgia">DoCmd.GotoRecord , , acGoTo, x</font face=georgia> should suffice.

    What I meant by subform controls on the main form is that each subform is in itself a control on the main form, and as such has a name. This name can be different from the name of the subform in the database window - you can change these two names independently of each other. I didn't mean to refer to controls on subforms.
    Usually, you only have a limited number of subforms on a main form, so it shouldn't be hard to find their names. But if you would like to list them, you could put the following procedure in a standard module (it could be improved to make it more user-friendly; this is just a simple example):

    Sub ListSubforms()
    Dim strForm As String
    Dim frm As Form
    Dim ctl As Control

    On Error GoTo ErrHandler

    strForm = InputBox("Enter form name")
    If strForm = "" Then Exit Sub
    DoCmd.OpenForm strForm, acDesign
    Set frm = Forms(strForm)
    For Each ctl In frm.Controls
    If ctl.ControlType = acSubform Then
    Debug.Print ctl.Name
    End If
    Next ctl

    ExitHandler:
    On Error Resume Next
    DoCmd.Close acForm, frm.Name, acSaveNo
    Set ctl = Nothing
    Set frm = Nothing
    Exit Sub

    ErrHandler:
    MsgBox Err.Description, vbExclamation
    Resume ExitHandler
    End Sub

    This procedure prompts for the name of a (main) form, then lists the names of all subforms (as controls) in the Immediate window of the Visual Basic Editor.

  5. #5
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Subform Not Open (A2k SR1)

    Hans,

    Thanks for the code on the subform controls. (Both you and Charlotte amaze we with how much you know....) I will try it once back in the office.


    As to the DoCmd.GotoRecord.... sometimes the obvious is just too obvious. I will try DoCmd.GotoRecord , , acGoTo, x as suggesgted without the reference to the subform which is already in focus.
    Regards,

    Gary
    (It's been a while!)

Posting Permissions

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