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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Current database info:

Status
Not open for further replies.

elziko

Programmer
Nov 7, 2000
486
GB
I need to find a way of returning the following:

Current form and which table it belongs to.

Thanks

elziko
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top