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

Creating a Global code

Status
Not open for further replies.

chippyles

Technical User
Nov 10, 2004
49
US
I have a subroutine that I have ON OPEN for a few of my forms. I would like to take that subroutine and make it so that for all of my forms that open to do this subroutine. How do I go about doing this??
 
in a module enter the following code
be careful with all the single and double quotes
and on the properties tab of the form enter =logform()
Public Function logform()
With DoCmd
.SetWarnings False
.RunSQL "INSERT INTO LOG_REPORT ([DATE],[USER],HOST,TASK)SELECT Now(),'" & Environ("username") & "','" & Environ("COMPUTERNAME") & "','" & ActiveForm.Name & "'"
.SetWarnings True
End With
End Function
 
What do I save the module as and do I put =logform() in the ON OPEN for the Form Properties?
 
1)What do I save the module as
any meaningful name
2)and do I put =logform() in the ON OPEN for the Form Properties?
that is correct
 
I have a compile error...

Invalid use of Me keyword

 
note i have changed from me.name to ActiveForm.Name
 
runtime error 424:
object required

I changed to your suggestions and I get this error now.
 
a bit of change is required
change this line to
Public Function logform()->Public Function logform(fromname)
.RunSQL "INSERT ........,'" & ActiveForm.Name & "'"-->
.RunSQL "INSERT ........,'" & fromname & "'"-->
and =logform() --> =logform("the name of the form")

 
Be aware that the module should not be one attached to a form or report - these are Class Modules and work slighlty differently.

Stewart J. McAbney | Talk History
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top