Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 2003
    Posts
    2

    Unanswered: Refresh parent form

    New to Access coding: hope my question doesn't sound too stupid.

    I have a form that has a listbox control the rowsource of which is a query. On that same form is a button that open another form for data entry. What I'm trying to do is to refresh the listbox display with the new records when the data entry form is closed.

    Since that data entry form can also be a stand-alone form by itself, I'd like to check whether it's initiated from the listbox form first. I have something like:

    strParentForm = Me.Parent.Name

    but I keep getting runtime error '2452' on that statement. I change it to a IF statement but still got the same error.

    Any hint appreciated.

  2. #2
    Join Date
    Apr 2003
    Location
    Homer, Alaska
    Posts
    15
    me.Parent refers to a parent form of a subform. It cannot be used with a form you're opening through a button.
    One way to do what you're trying is to open the form "Modally"
    and refresh the listbox when it is closed. When the form is opened modally the code that opened it does not continue running until the form is closed.

    ie:

    Private Sub Button_Click()

    DoCmd.OpenForm "EntryFormName", acNormal, , , acFormAdd, acDialog
    me.Listbox.Requery

    End Sub

  3. #3
    Join Date
    Apr 2003
    Posts
    2

    Smile

    Thanks! That works for me.

  4. #4
    Join Date
    Oct 2003
    Posts
    19

    Talking Refresh Parent Form

    Hi,

    I don't know how to use VisualBasic, but I get around pretty well with Macros and expressions. This is my question:

    When the focus is in a subform, I can't figure out how to get a macro to change the focus from that subform to the parent form. I've had to create a "refresh" button on the parent form and I have to click it manually everytime I want the calculations in the subform to update.

    I've tried using a macro with
    1. "GoToControl" and referring to me.parent, or me.parent.main form (the name of my parent form), or me.parent.[Employee] (the name of the one field in the parent form).

    Sorry if I sound new at this - any help would be very appreciated!!

    Thanks.

    Originally posted by tsulczynski
    me.Parent refers to a parent form of a subform. It cannot be used with a form you're opening through a button.
    One way to do what you're trying is to open the form "Modally"
    and refresh the listbox when it is closed. When the form is opened modally the code that opened it does not continue running until the form is closed.

    ie:

    Private Sub Button_Click()

    DoCmd.OpenForm "EntryFormName", acNormal, , , acFormAdd, acDialog
    me.Listbox.Requery

    End Sub

  5. #5
    Join Date
    Apr 2003
    Location
    Homer, Alaska
    Posts
    15
    Yo can refer to any open form in your database directly by using
    "form_" & the form name.
    ie.
    if your form's name is "frmMainForm" and the control you want to set the focus to is "txtEmployee" you can use this expression:
    form_frmMainForm.txtEmployee.SetFocus

    hope this helps....

  6. #6
    Join Date
    Oct 2003
    Posts
    19
    Thanks friend!

    I actually found out a way to make it work with macro commands on my own shortly after I posted this.

    However I'm going to try it your way as well. I'm new to news forums, but I can't tell you how releaved I am to find that there are people like yourself that will take the time to help.

    Question: Where do I enter this expression? In a code module? Directly in an event property? In an Event Procedure?

    Thanks again!

    Originally posted by tsulczynski
    Yo can refer to any open form in your database directly by using
    "form_" & the form name.
    ie.
    if your form's name is "frmMainForm" and the control you want to set the focus to is "txtEmployee" you can use this expression:
    form_frmMainForm.txtEmployee.SetFocus

    hope this helps....

  7. #7
    Join Date
    Apr 2003
    Location
    Homer, Alaska
    Posts
    15
    Ok, I played around with this a little bit & here's what I found:
    if you want to create it in an Event Procedure use:
    form_FormName.ControlName.SetFocus

    If you're going to type it in directly into the event property use:
    =forms!FormName.ControlName.SetFocus

    If you're going to use a Macro Use:
    1. Action: OpenForm with the FormName in the "Form Name" property
    2. Action: GoToControl with just the name of the control in the "Control Name" property

Posting Permissions

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