Calling a function

L

LJG

I Have converted a Macro to a VBA function and need to know how I now call
that function?

Thanks
 
K

kabaka

Your function is in a module now right?

From wherever you wish to call it from, just call the function along with
its arguements. For example:

IN YOUR MODULE
Function test(i as integer)
....do stuff
end function

IN YOUR FORM
Private Sub Form_Open()
test(5)
end sub

that's all there is to it.
 
L

LJG

Hey,

Tried that but keep getting an error when trying to save it as an on_Click
event:

Private Sub cmdExportFile_Click()
modExportSoftware()
End Sub

Is what I have, but I keep getting a syntax error when I try to save, and
highlights the 'Private Sub' line

Thanks
Les
 
K

kabaka

What is the error message? A couple things I'd check:
1) make sure that your OnClick() event is set up correctly (to check go to
the design view of your form, select your control, open it's properties to
the event tab, go to the On Click event where it should say 'Event Procedure'
and click the '...' button. If it comes up to your Sub as below, then that
is set up correctly.
2) make sure you've passed your functions the correct number of arguements.
3) if your function requires more that one arguement, it requires that you
assign the value of the function to a variable (and I'm not sure why) as in:

Private Sub cmdExportFile_Click()
dim temp
temp = modExportSoftware(arg1, arg2)
End Sub

Would I be correct in assuming that your function (in your module) compiled
& saved ok? If that doesn't help, I'll need more details.
 
Top