Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 2nd, 2005, 11:07 PM
Registered User
 
Join Date: Mar 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Addressing a control on a form from another form

Hey folks,

I'm designing a form with 2 (nested) subforms on it. I need to clear the contents of the listboxes on the subforms from the main form using VBA before I populate them - is there a way to do this?

The way the form is structured right now is, the main form populates its own listbox, then creates a query which the subform uses to later populate its own listbox.

Simple diagram: Form1(Form2(Form3)))

The code used to create the query in Form1:

Set qry = dbs.CreateQueryDef("qryConSelect", "SELECT tblConsultants.ConsultantName, tblConsultants.Phone, tblConsultants.RelationshipGrade, tblConsultants.Tiering " & _
"FROM tblConsultants WHERE (((tblConsultants.CallerID)= " & Me![CallerID] & "));")

This code then runs on Form2 to populate its listbox (this runs in Form_Current):

    checkFlag = False
    For Each qdf In dbs.QueryDefs
        If qdf.Name = "qryConSelect" Then checkFlag = True
    Next qdf

    If checkFlag = True Then
        Set rst = dbs.OpenRecordset("qryConSelect")
        MSListBox21.Clear
        If rst.RecordCount <> 0 Then
            rst.MoveLast
            rst.MoveFirst
            For i = 1 To rst.RecordCount
                MSListBox21.AddItem CStr(rst![ConsultantName])
                rst.MoveNext
            Next
        End If
    End If

The form then makes another query which its subform in turn uses to populate its listbox.

This works well, but the problem is that when the user clicks on the very top list box, the ones underneath are already populated. They clear & repopulate when clicked, but until they are they display misleading data. Ideally, I'd like to be able to clear MSListBox21 right when I make thge very first query, in Form1, but I can't access it as it's not a control on it. Is there a way to access a control on another form from within VBA to fix this?

Otherwise, any suggestions on where to stick "MSListBox21.Clear" on the subform?

 
Old March 3rd, 2005, 12:05 AM
Registered User
 
Join Date: Mar 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Nevermind... figured it out.

Form_frmMyform.Control.Property = x






Similar Threads
Thread Thread Starter Forum Replies Last Post
calling control in one form from another form netfresher C# 3 November 8th, 2006 10:05 AM
Addressing form from module MKri VB.NET 2002/2003 Basics 18 December 23rd, 2005 10:22 AM
How many control arrays can be placed in a form ramk_1978 Beginning VB 6 3 February 21st, 2005 07:57 AM
adding a control onto a form yun VS.NET 2002/2003 1 July 2nd, 2004 03:15 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.