Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to find RecordSource for AllForms item opened with DoCmd

Status
Not open for further replies.

SBendBuckeye

Programmer
May 22, 2002
2,166
0
0
US
Hello all,

I am opening up another access file and iterating the controls collection. I have a variable named AccessApp that I use to get a reference to a given form using DoCmd as follows:

AccessApp.DoCmd.OpenForm "MyFormName", acDesign, , , acFormEdit, acWindowNormal

I can iterate over the controls collection and various form properties using AccessApp.Forms(formName) but the RecordSource property does not return anything. Can someone show me how to get the RecordSource property for a form opened in design view using VBA?

Thanks in advance for any ideas and/or suggestions!
 
I have a variable named AccessApp that I use to get a reference to a given form using DoCmd
No that is not true. AccessApp is not a variable nor does it give you a reference to a form. It is the Access Application object.

Public Sub getProp(frmName As String)
Dim frm As Access.Form
dim cntrl as access.control
DoCmd.OpenForm frmName, acDesign
Set frm = Forms(frmName)
'code to return form props
with frm
Debug.Print .RecordSource
debug.print .otherProperties
end with
for each cntrl in frm.controls
code to return control props
next cntrl
End Sub
 
Hello,

Sorry for the lack of clarity in my original post. I think we are saying the same thing, only I am using a separate Access.Application object to open another Access file from inside my current Access file via VBA.

Code:
Dim AccessApp As Access.Application
Set AccessApp = CreateObject("Access.Application")

AccessApp.OpenCurrentDatabase "YourDatabasePath"

AccessApp.DoCmd.OpenForm "YourFormName", acDesign, , , acFormEdit, acWindowNormal

For Each ctl In AccessApp.Forms("YourFormName").Controls
    Debug.Print ctl.Name, etc
Next

The code is actually working correctly. When I posted the message earlier it was because I had a brain cramp due to testing with some forms with no RecordSource. Thanks for taking time to respond.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top