problems passing form object to a subroutine

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi guys,

I have 4 order forms that require the same actions
I would like to make a subroutine that I can pass the form object to
objectify these actions

I have a call to a procedure:
Library.SetOrderLineFields (Me)

and the procedure:

Public Sub SetOrderLineFields(frm As Variant)
' Set all fields from Items combo box

With frm
' Actions for setting fields

Dim sItemTable As String
' If item is a group item
sItemTable = .Item.Column(6))

etc...
I have tried changing the argument type from as form /as object/as variant

with the argument as a form or object the error:
type mismatch on the call subroutine line

if I make the argument a variant I get an error on the combo box field array

Wrong number of arguments or invalid property assignment (Error 450)
on the following line

..Item.Column(6)

not sure how to accomplish this,

Thanks in advanced
david
 
David,

Try passing the form's name as an argument, and then in your procedure
refre to the form by name. That is to say, the call should be something
like:

Library.SetOrderLineFields (Me.Name)

and the sub:

Public Sub SetOrderLineFields(frm As String)
' Set all fields from Items combo box

With Forms(frm)
' Actions for setting fields

Dim sItemTable As String
' If item is a group item
sItemTable = .Item.Column(6))

etc...

HTH,
Nikos
 
Hi:

Thank you for responding. I hoped your solution worked. I tried it and
received:
cannot find the form "invoielinedetail" in this procedure...

Also, just to give you some more information
the subroutine is public and is a separate module, i don't know if this has
any relevance.

Any other suggestions....
Thanks again
d
 
Hi again,

Thanks for responding. I had hoped your method would work. I tried it and
received
"Cannot find form named invoicedetails in the subroutine....

Just some extra information:
The subroutine is in a separate module and is a public sub.

Cheers,
David
 
dp said:
Hi guys,

I have 4 order forms that require the same actions
I would like to make a subroutine that I can pass the form object to
objectify these actions

I have a call to a procedure:
Library.SetOrderLineFields (Me)

and the procedure:

Public Sub SetOrderLineFields(frm As Variant)

if the line

Library.SetOrderLineFields (Me)

is called directly from code in the form's module and not from a
public sub in a seperate module then you should not be having a
problem.

The called sub routines signature should be

Public Sub SetOrderLineFields(frm As Access.Form)
'body
End Sub
 
thanks for responding

funny, i figured out a simple way to do it that worked.

Dont pass the variable type in the arg

Public Sub SetOrderLineFields(frm)
'body
End Sub

thanks
 
David,

The use of the Me keyword in your original code led me to believe the
code was in the form's own module, where my proposed solution would have
worked. In a general module, though, you need to use something like:

frmname = "invoicedetails"
Library.SetOrderLineFields (frmname)

or, if the sub is called from several forms, you can pass the form name
to the sub when calling it.

HTH,
Nikos
 
Back
Top