Wrox Programmer Forums
|
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 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 February 20th, 2008, 07:02 AM
Authorized User
 
Join Date: Oct 2007
Posts: 46
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via MSN to debbiecoates
Default form object

In my database, when I call certain funtions, i capture the form name of the form that called it in a string.

Is there a way to then make a form object from the string

ie, gActiveForm is the form that called the function
then I want to do something like this

Dim frm As Form
Set frm = gActiveForm

with frm
.heading1 = "Whatever"
.heading2 = "something else"
end with

.heading1 and .heading2 are fields that always appear on the forms that called the function

Would be grateful for any advise




 
Old February 20th, 2008, 04:20 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Hi Debbie.

(1st a pet peeve: ie stands for the latin, id est, which means, "that is." Eg stands for the latin exempli gratia, which literally means "example given," which in English is, "For example." You (I'm sure) meant eg, instead of ie.)

You cannot do what it is that you have laid out here, but you can do something that produces the type of results that you seem to be indicating.

If you make a generic form, with a control named heading1, a control named heading2, etc., then you can create an object of that class, and treat it as you have indicated.

Let me back up, and fill in that forms are specialized classes. In many ways they behave exactly like classes. You can create a variable of the type of the form, just as with any class.

Let's say you have a form "frmYuh." You can
Code:
    Dim frm as New frmYuh
Additionally, you can add your own properties to a form module, and they will be properties of the form object instantiated from it.
Code:
Option Explicit

Private MyName As string

Public Property Let InstName(Name As String)
    MyName = Name
End Property
Public Property Get InstName() As String
    If InstName = "" Then
        InstName = "<I have no name...>"
    Else
        InstName = MyName
    End If
End Property
Then, when an instance of this class is created, you can address that property
Code:
    frm.InstName = "gActiveForm"
There is no way to find this object though...

But you can make an array
Code:
    Dim frms() As frmYuh
Then, when you want to create a new one, ReDim the array (with Preserve...), and add your new form instance. When it is time to find it, loop through the array looking at the .InstName property, till you find the one you are after.

If you close one of them
Code:
    frms(3) = Nothing
there will be a gap in the array...

You might want to use a Collection object instead. Then you can use the .Key property directly to access your form instances.

Does that help?





Similar Threads
Thread Thread Starter Forum Replies Last Post
FORM Object hides drop-down nancy HTML Code Clinic 2 April 7th, 2006 08:15 AM
Form doesn't appear in object browser kuznickic Access VBA 4 November 8th, 2005 05:39 AM
Tab Automatically To Next Object on Form ritag HTML Code Clinic 3 August 4th, 2004 09:49 AM
instantiate a form object by its name in MS Access sky2000 Access VBA 1 May 6th, 2004 03:44 AM
Displaying OLE object field in a form Rick Neifeld Access VBA 0 December 24th, 2003 02:16 PM





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