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

Call a form from a Module 1

Status
Not open for further replies.

nycbigapple

Technical User
Apr 4, 2006
33
0
0
US
Hi,

I am trying to call this from a module but it isn't working. It works when I put it as a private but I will be calling this many times in a form so I don't want to have a bunch of code.

!FormName = Me.Form.Name

Public Function fctT() As Boolean
........
'!CompName = strCompN
!Login = Now
!LastUpdate = Now
!FormName = Me.Form.Name
.Update
.......

That one single line doesn't work in the module, keep getting errors
 
There seems to be a lot missing in your question and the piece of code you have shown.

!FormName = Me.Form.Name
For !FormName to mean anything, there has to be a "With" statement in the code somewhere above this line. What is the "With"?

Within the "Public Function fcT() as Boolean" you have more lines preceeded by "!" and still no idea what the "With" will be for these lines. For you to have an ".Update" at the bottom suggests a recordset.

Your last line states that one single line doesn't work in the module, keep getting errors. My first read of this statement, I thought there was one single line, but you did not say which single line. After re-reading several times, it came to me that you could be saying, "Every line in this module produces an error." Well, it would really help to know what these errors are.

Plus, you say you are trying to call this from a module, but it won't work unless you have it coded as Private. But that is confusing because I am now thinking that you mean that all of these lines produce an error.

More specific information would really help here.
 
Inititally, I had this code as an Event Procedure and it works fine on FORM OPEN. That is why I did not list the code above and below.

When I created a module and calling to this function from a form
I am having a problem with !FormName = Me.Form.Name

I get an error stating that !FormName = Me.Form.Name is not reconized. Saying that ME is not valid.

I am trying to get the name of the form for reporting purposes. Because I will be using this code on many forms,I thought it would be easier to call from a module
 
It sounds like you are calling a function from your code, at which point "Me" is not recognized because "Me" only refers to the form or report it is in. So, when you call this function from a form, pass "Me" as one of the parameters.
ie: RetVal = MultiFormFunction(Me as Form, Parm1, Parm2).
The function would be written like this:
Function MultiFormFunction(frm as Form, Parm1, Parm2)
Then within the function you have written, replace "Me" with "frm".

Of course if you have written a Sub rather than a Function, don't make the sub = to RetVal (return value) and the names I have used are for illustration purposes only.
 
How are ya nycbigapple . . .

You have to [blue]fully qualify[/blue] the Form/Object name in a [blue]public[/blue] sub/function. sing a form as the object it would look like:
Code:
[blue]Public Function fctT() As Boolean
   Dim frm As Form
   
   Set frm = Forms![purple][b]YourFormName[/b][/purple]
   
   With frm
        !CompName = strCompN
        !Login = Now
        !LastUpdate = Now
        .Update
   End With

End Function[/blue]

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top