Results 1 to 9 of 9
  1. #1
    Star Lounger
    Join Date
    Mar 2001
    Posts
    56
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Activating a query in forms (2000)

    I have a form that consists of five tabs. The first tab is owner information that was created from a table and a list of residents occupying the property also created from an underlying table (subform). The third tab was created from a query of which the first three columns is a list of residents taken from the resident table. My problem is when under the first tab I enter residents, then go to the third tab, they do not show up unless I close the form and re-open it again, at which time they do show up. Is there anyway to make this query run when just moving to the third tab without closing the form? I hope I have been clear enough. Thanks. Dorothy

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

    Re: Activating a query in forms (2000)

    You could requery the subform in the third tab when that tab is activated; you can use the On Change event of the tab control for this. The Value of the tab control is the zero-based index of the active tab.

    Private Sub TabControl_Change()
    If Me.TabControl.Value = 2 Then ' third tab, zero-based
    Me.SubForm.Requery
    End If
    End Sub

    Replace TabControl with the name of the tab control, and SubForm with the name of the subform as a control on the main form (this is not necessarily the same as the name of the name of the subform in the database window.)

  3. #3
    Star Lounger
    Join Date
    Mar 2001
    Posts
    56
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Activating a query in forms (2000)

    Hi Hans,

    I am not sure what or where the On Change event of the tab control is. I also don't understand the value of the tab control is the zero-based index of the active tab. Sorry. Would you be able to guide me a little more. Thanks. Dorothy

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

    Re: Activating a query in forms (2000)

    Open your form in design view.
    Select the tab control as a whole (click immediately to the right of the last tab on the tab control, or select the name of the tab control from the Object dropdown list in the Formatting toolbar)
    Activate the Event tab of the Properties window.
    Click in the box labeled On Change.
    Select [Event Procedure] from the dropdown list in this box.
    Click the builder button (the ...) to the right of the dropdown arrow.
    This will start the Visual Basic Editor and open the code module associated with the form.
    You'll see
    <code>
    Private Sub TabControl_Change()

    End Sub
    </code>
    where TabControl is the name of your tab control. You can now type code, or copy/paste it from my previous reply (don't forget to substitute the correct names)

    The tab control has a Value property that is only available in Visual Basic; this value indicates which tab is active. "Zero-based" means that the value is 0 if the first tab is active, 1 if the second tab is active, 2 if the third tab is active, etcetera. The code I posted checks whether the third tab is active by looking for Value = 2.

  5. #5
    Star Lounger
    Join Date
    Mar 2001
    Posts
    56
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Activating a query in forms (2000)

    Much clearer, thank you, but does not seem to be working. The name of the third tab is "Pool Information", with a space between "pool" and "information", and when I click up the subform and look at properties the name is SubFrmPoolValOwner. I used the following code:

    Private Sub PoolInformation_Change()
    If Me.TabControl.Value = 2 Then ' third tab, zero-based
    Me.SubFrmPoolValOwner.Requery
    End If

    End Sub

    One problem is that I could not use "Pool Information" in the coding with a space in between it, so I closed it. When testing this ,under the first tab I enter names in a form (with an underlying table) then when I go to the third tab - Pool Information - the subform is blank. Does not even show the fields any longer. When I close the form and reopen the info is then present under the third tab. What am I doing wrong? Thanks.

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

    Re: Activating a query in forms (2000)

    You should not use the name of the third tab, but the name of the tab control as a whole. See screenshot.

  7. #7
    Star Lounger
    Join Date
    Mar 2001
    Posts
    56
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Activating a query in forms (2000)

    Used the following code:

    Private Sub Tab Control: TabCtl0_Change()
    If Me.TabControl.Value = 2 Then ' third tab, zero-based
    Me.SubFrmPoolValOwner.Requery
    End If

    End Sub

    Still is not working. Dorothy

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

    Re: Activating a query in forms (2000)

    From the first line, I assume that the name of your tab control is TabCtl0, so try

    Private Sub TabCtl0_Change()
    If Me.TabCtl0.Value = 2 Then ' third tab, zero-based
    Me.SubFrmPoolValOwner.Requery
    End If
    End Sub

    The name is used in the Private Sub line and the same name must be used in the following line.

  9. #9
    Star Lounger
    Join Date
    Mar 2001
    Posts
    56
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Activating a query in forms (2000)

    Thank you, thank you, thank you. It worked. Dorothy

Posting Permissions

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