Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 2nd, 2005, 11:07 PM
Registered User
Join Date: Mar 2005
Location: , , .
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")
        If rst.RecordCount <> 0 Then
            For i = 1 To rst.RecordCount
                MSListBox21.AddItem CStr(rst![ConsultantName])
        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?

Reply With Quote
  #2 (permalink)  
Old March 3rd, 2005, 12:05 AM
Registered User
Join Date: Mar 2005
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts

Nevermind... figured it out.

Form_frmMyform.Control.Property = x

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 09:20 PM.

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