The "Screen.ActiveForm" property returns a reference to the Form object that currently has the focus. Keep in mind that if no form currently has the focus, the ActiveForm function will raise an error that you much trap.
From the form object, you can get the name from the .Name property:
Dim frm As Form
Set frm = Screen.ActiveForm ' error may occur here
strFormName = frm.Name
If you only use tables as your form record source, the form.RecordSource will have the name of the table. Otherwise you'd have to determine whether it's a query, and parse the query SQL statement to extract the name(s) of the table(s) it uses. It would actually be easier to create a Public function in each form called, for example, BaseTable, and set it to the value you need:
(in form)
Public Function BaseTable() As String
BaseTable = "My Table Name"
End Function
(in code that needs to get form information)
Dim frm As Form, strTableName As String
Set frm = Screen.ActiveForm
strTableName = Forms(frm.Name).BaseTable Rick Sprague
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.