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

Function current form name?? 1

Status
Not open for further replies.

tigersden

Technical User
Apr 16, 2003
81
GB
Hi All,
I have a couple of functions which need to be called from different forms. At present I have referenced the fields as:
Forms![frmTEST]!txtMyRef
What I would like to happen is whatever form the function is called from that forms name is automatically passed to the function.
Could someone please post a code sample of the fuction I would need to do this.
Thanks in advance
Tim
 
Hi!

MyFunction Me.Name

will call

Public Function MyFunction(FormName As String)

sending MyFunction the name of the calling form. You don't say what you want to do with the form's name, but assuming you want to generalize the piece of code above you can use the following code:

Forms(FormName)!txtMyRef

You can also generalize the control name by sending the name of the control to the function also and using:

Forms(FormName).Controls(ControlName)

Alternatively you can use the Screen Object to get the name of the active form:

Screen.ActiveForm.Name

And the active control too, if that would be useful.

hth


Jeff Bridgham
Purdue University
Graduate School
Data Analyst
 
Hi
Do you mean something like:
[tt]MyVar = MyFunction("FormName","FieldName")[/tt]

[tt]Function MyFunction(FormName, FieldName)
MsgBox Forms(FormName).Controls(FieldName)
End Function[/tt]

Or did you have a different idea in mind? [ponder]
 
Hi,
Thanks both for replying.
I wanted to place the forms name in a sql statement in another function.
I wanted to generalize the code, so using jebry's example
(I know this will sound really stupid to you but I am going to ask anyway.)

Public Function MyFunction(FormName As String)
???What goes here???
end function

Also how would this be included in the sql statement am on the right lines with
Other SQl .....
& " HAVING (tblReview.RiskRef)= " & Forms!(FormName)!txtRiskRef

Thanks again.
Tim

 
Hi Tim!

If I understand correctly then you would do this:

Public Function MyFunction(FormName As String)

Other SQl .....
& " HAVING [tblReview.RiskRef] = " & Forms(FormName)!txtRiskRef

end function

If RiskRef is alphanumeric then you would need:

Public Function MyFunction(FormName As String)

Other SQl .....
& " HAVING [tblReview.RiskRef] = '" & Forms(FormName)!txtRiskRef & "'"

end function

I hope that is what you are looking for?



Jeff Bridgham
Purdue University
Graduate School
Data Analyst
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top