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

get form name

Status
Not open for further replies.

matrixindicator

IS-IT--Management
Sep 6, 2007
418
BE
Hoy, to make my code more resuable in different forms I need to pas the name of the form into a variable. I search on previous thread but could find the right syntaxis. How to ?

Code:
Dim frmName As String
frmName = Forms!Form.Name

Forms![& frmName &].RecordSource = Forms![& frmName &].RecordSource

 
How about:

Forms(frmName).RecordSource = Forms(frmName).RecordSource
 
no Remou. Thats just a trial to use the variable.
I need to get the name of the form where I am in. The oode is not working. On click on a button he should find out the name of the form. I use the same procedure in more then one form.

regards,
 
Do you want the name of the current form? If so, Me.Name will return the name. You can pass Me, if you wish to pass an object:

SomeFunction Me, OtherVar
SomeFunction Me.Name, OtherVar
 
yep, current form but ...

using your proposal he said "invalid use of key word
 
Code:
Sub ImportLinkedTable1()
Dim frmName As String
frmName = Form!Me.Name
MsgBox frmName
 
If you are not running the code in a form module, you can use Screen.ActiveForm, if you are running the code in a form module, Me.Name should work. Alternatives include iterating through the forms collection to find any open form, and referring to forms by index (Forms(0)).
 
thanks Remou, your gave me the direction, code below works.

Code:
Dim frmCurrentForm As Form
Set frmCurrentForm = Screen.ActiveForm
Dim frmName As String
frmName = frmCurrentForm.Name

DoCmd.SetWarnings False
If IsNull(Forms(frmName).IDdocu) Then ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top