Accessing Controls in an Unopened Form or Report

  • Thread starter Thread starter Sam Hobbs
  • Start date Start date
S

Sam Hobbs

I really thought I saw a sample in the Access documentation of accessing
controls in a form or report without the form or report being opened, but
now I sure can't find it. I probably misunderstood the sample and it just is
not possible to do it. If anyone knows of a sample such as this or what
Access object to use or anything like that then I am interested in it. I
don't need much information about how to do this, I can figure it out if I
know what to look at.
 
Very limited information is available through the AllForms collection
(Access 2000 and later), or the Documents collection (DA0).

Realistically, you need to open each form (hidden if you wish) to get at the
info.

To just get a list of the names of the forms:
SELECT [Name] FROM MsysObjects
WHERE (([Type] = -32768) AND ([Name] Not Like '~*'))
ORDER BY MsysObjects.Name;
 
Thank you, Allen, and yes it is possible to get information about Access
objects, but I don't know how to use that information to get to the
controls. I do know that the AllForms collection contains an AccessObject
object for each form, but it is only generic AccessObject object
information.

I am familiar with queries such as the one you have provided here; I have
seen that one in your web site.


Allen Browne said:
Very limited information is available through the AllForms collection
(Access 2000 and later), or the Documents collection (DA0).

Realistically, you need to open each form (hidden if you wish) to get at
the info.

To just get a list of the names of the forms:
SELECT [Name] FROM MsysObjects
WHERE (([Type] = -32768) AND ([Name] Not Like '~*'))
ORDER BY MsysObjects.Name;

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Sam Hobbs said:
I really thought I saw a sample in the Access documentation of accessing
controls in a form or report without the form or report being opened, but
now I sure can't find it. I probably misunderstood the sample and it just
is not possible to do it. If anyone knows of a sample such as this or what
Access object to use or anything like that then I am interested in it. I
don't need much information about how to do this, I can figure it out if I
know what to look at.
 
From your reply, you probably already know how to create a fuction like the
one below. AFAIK, that's the only way to get at all the properties of the
controls of the forms.

Function ShowFormControls()
Dim accObj As AccessObject
Dim frm As Form
Dim ctl As Control
Dim strDoc As String

For Each accObj In CurrentProject.AllForms
strDoc = accObj.Name
DoCmd.OpenForm strDoc, acDesign, WindowMode:=acHidden
For Each ctl In Forms(strDoc).Controls
Debug.Print strDoc & "." & ctl.Name, _
ControlTypeName(ctl.ControlType)
Next
DoCmd.Close acForm, strDoc
Next

Set ctl = Nothing
Set frm = Nothing
Set accObj = Nothing
End Function

Function ControlTypeName(n As Long) As String
Select Case n
Case acBoundObjectFrame
strReturn = "Bound Object Frame"
Case acCheckBox
strReturn = "Check Box"
Case acComboBox
strReturn = "Combo Box"
Case acCommandButton
strReturn = "Command Button"
Case acCustomControl
strReturn = "Custom Control"
Case acImage
strReturn = "Image"
Case acLabel
strReturn = "Label"
Case acLine
strReturn = "Line"
Case acListBox
strReturn = "List Box"
Case acObjectFrame
strReturn = "Object Frame"
Case acOptionButton
strReturn = "Object Button"
Case acOptionGroup
strReturn = "Option Group"
Case acPage
strReturn = "Page (of Tab)"
Case acPageBreak
strReturn = "Page Break"
Case acRectangle
strReturn = "Rectangle"
Case acSubform
strReturn = "Subform/Subrport"
Case acTabCtl
strReturn = "Tab Control"
Case acTextBox
strReturn = "Text Box"
Case acToggleButton
strReturn = "Toggle Button"
Case Else
strReturn = "Unknown: type" & n
End Select
ControlTypeName = strReturn
End Function

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Sam Hobbs said:
Thank you, Allen, and yes it is possible to get information about Access
objects, but I don't know how to use that information to get to the
controls. I do know that the AllForms collection contains an AccessObject
object for each form, but it is only generic AccessObject object
information.

I am familiar with queries such as the one you have provided here; I have
seen that one in your web site.


Allen Browne said:
Very limited information is available through the AllForms collection
(Access 2000 and later), or the Documents collection (DA0).

Realistically, you need to open each form (hidden if you wish) to get at
the info.

To just get a list of the names of the forms:
SELECT [Name] FROM MsysObjects
WHERE (([Type] = -32768) AND ([Name] Not Like '~*'))
ORDER BY MsysObjects.Name;

message
I really thought I saw a sample in the Access documentation of accessing
controls in a form or report without the form or report being opened, but
now I sure can't find it. I probably misunderstood the sample and it just
is not possible to do it. If anyone knows of a sample such as this or
what Access object to use or anything like that then I am interested in
it. I don't need much information about how to do this, I can figure it
out if I know what to look at.
 
See the following for a discussion I created about queries similar to what
you have provided.

http://groups.google.com/groups?q=g...lr=&[email protected]


Allen Browne said:
Very limited information is available through the AllForms collection
(Access 2000 and later), or the Documents collection (DA0).

Realistically, you need to open each form (hidden if you wish) to get at
the info.

To just get a list of the names of the forms:
SELECT [Name] FROM MsysObjects
WHERE (([Type] = -32768) AND ([Name] Not Like '~*'))
ORDER BY MsysObjects.Name;

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Sam Hobbs said:
I really thought I saw a sample in the Access documentation of accessing
controls in a form or report without the form or report being opened, but
now I sure can't find it. I probably misunderstood the sample and it just
is not possible to do it. If anyone knows of a sample such as this or what
Access object to use or anything like that then I am interested in it. I
don't need much information about how to do this, I can figure it out if I
know what to look at.
 
Yes, you are correct. the And operator in VBA can be interpreted as logical
or bitwise, whereas it is logical only in JET.

JET 4 does have a BAND operator, but it works only if you execute your query
under ADO. Since the query interface uses DAO (the native Access library),
you can't use the BAND operator there, only in ADO code.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.


In another thread, you said:
---------------------------------------
I have the following in a module that works:


Const DB_SYSTEMOBJECT = &H80000002

Public Function IsSystemObject(Flags)
IsSystemObject = (Flags And DB_SYSTEMOBJECT)
End Function


However when I use "Flags And 2147483650" in a query, I don't get the same
results as I do when I say "IsSystemObject(Flags)". Is a way to do the
equivalent of the IsSystemObject Function except in a query directly?

I guess the problem is that the And operator has dual purposes; it is either
a logical or a bitwise operator. So I can probably figure out a way to get
it to be a bitwise operator, but if someone does not mind enlightening me
with their experience, then that will problably help.

Note: Some people will recognize that this is testing the Flags field of the
MSysObjects table to determine if the object is a system
object.---------------------------------------"Sam Hobbs"
See the following for a
discussion I created about queries similar to what
you have provided.

http://groups.google.com/groups?q=g...lr=&[email protected]


Allen Browne said:
Very limited information is available through the AllForms collection
(Access 2000 and later), or the Documents collection (DA0).

Realistically, you need to open each form (hidden if you wish) to get at
the info.

To just get a list of the names of the forms:
SELECT [Name] FROM MsysObjects
WHERE (([Type] = -32768) AND ([Name] Not Like '~*'))
ORDER BY MsysObjects.Name;


message
I really thought I saw a sample in the Access documentation of accessing
controls in a form or report without the form or report being opened, but
now I sure can't find it. I probably misunderstood the sample and it just
is not possible to do it. If anyone knows of a sample such as this or
what Access object to use or anything like that then I am interested in
it. I don't need much information about how to do this, I can figure it
out if I know what to look at.
 
Back
Top