reading Caption property of unopened form

T

tina

hi folks,

i'm using the following code to build a listbox control's RowSource, on a
form's Load event. it's a two-column listbox, first column being the object
name of certain forms in the database (not including the form that's
loading), and second column being the Caption of each form, as

Private Sub isRowSource()

Dim frm As AccessObject, str As String, db As Object

Set db = Application.CurrentProject

For Each frm In db.AllForms
If Left(frm.Name, 1) = "s" And InStr(frm.Name, "_") = False Then
str = str & frm.Name & ";" & frm.Caption & ";"
End If
Next

Me!lstTable.RowSource = str

End Sub

the frm.Name reference works fine, but obviously the frm.Caption reference
is bogus. how can i retrieve the value of the Caption property of a form
that is not currently open? or is it not possible?

tia, tina
 
M

Mark A. Sam

Tina,

If a form is closed, the captions is static and known. It is what it is.
It can be changed, dynamically, when the form is open. Open the form in
design view and read what it is. That is what it will be when the form is
closed.

God Bless,

Mark A. Sam
 
T

tina

thanks, hon, but i already know what the Caption property is, and how it
works in a form. as i said, i'm trying to retrieve the value of the property
from *closed* forms in my VBA looping code, in order to dynamically build a
listbox control's RowSource.

anyone know how to do that, or if it's possible? tia, tina
 
D

Douglas J Steele

You have to open the form (you can do it hidden), retrieve the caption, and
then close the form again.

No other way, as far as I know.
 
G

Guest

It's not possible.

Open the form in design mode, or better, add a table that lists the
form names and the caption that goes with each form. (better,
because the stupid 'must have exclusive access' rules cause
problems if you open forms in design mode, and you can't
do it in an mde anyway).

(david)
 
M

Mark A. Sam

Sorry I didn't read your request carefully. Doug's method is the only way I
can see to do it, not knowing what the forms will be.

God Bless,

Mark
 
J

jalewis999

I'm a beginner but try this or something similar. I think it opens the form
and closes it. I hope it helps
Private Sub Command0_Click()
Dim test As Form
Set test = New Form_Menu1
Debug.Print test.Caption
End Sub

John
 
F

fredg

thanks, hon, but i already know what the Caption property is, and how it
works in a form. as i said, i'm trying to retrieve the value of the property
from *closed* forms in my VBA looping code, in order to dynamically build a
listbox control's RowSource.

anyone know how to do that, or if it's possible? tia, tina

To cycle through the forms:

Public Sub FormCaptions()
Dim db As Database, doc As Document
Set db = CurrentDb

On Error GoTo Err_Handler

For Each doc In db.Containers("Forms").Documents
DoCmd.OpenForm doc.Name, acDesign, , , , acHidden

Debug.Print doc.Name,
Debug.Print Forms(doc.Name).Caption

DoCmd.Close acForm, doc.Name
Next

Exit_FormCaptions:
Set db = Nothing
Exit Sub
Err_Handler:
MsgBox "Error #: " & Err.Number & vbNewLine & Err.Description
Resume Exit_FormCaptions

End Sub
 
T

tina

thanks for your time and answers, everyone! :)


tina said:
thanks, hon, but i already know what the Caption property is, and how it
works in a form. as i said, i'm trying to retrieve the value of the property
from *closed* forms in my VBA looping code, in order to dynamically build a
listbox control's RowSource.

anyone know how to do that, or if it's possible? tia, tina


on
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top