Problem w/ Global Variables

J

John G

in my application, i have multiple forms. i have some
function declared as public in my module. now i know that
i can't return a value from a function to any form unless
i create another function in the module that sets another
variable to that value (i.e. if the function is mv1 and i
call it on form1 then for form2 to recognize it i have to
create another function in the module that sets another
variable x=mv1 and then in form2 i refer to x). i've done
this but when i get an error saying "argument is not
optional". i don't know what this means or what i'm doing
wrong....

the first function is as follows:

public function mv1(tbl as string) as double
mv1=DAvg("[field8]", tbl, "[ID]"<60)
end function


then the next one is:

public function setmv1() as double
setmv1=mv1
end function

i get the error on "setmv1=mv1"

any suggestions. thanx in advance.
john
 
E

Eric

I'm not quite sure I understand why you wrote this:
now i know that
i can't return a value from a function to any form unless
i create another function in the module that sets another
variable to that value

You can most certainly get a value from a function without
any errors occuring. Example:
--------------------------------------------------
Private Sub Form_Open(Cancel As Integer)
If me.txtSomeValue = RunMyFunction() Then
Debug.Print "This Works"
End If
End Sub

Private Function RunMyFunction() as Double
RunMyFunction = 2+2
End Function
--------------------------------------------------

I think I may be missing something and you'll have to
clarify.

Regards,
Eric
 
J

John G

i understand what you're saying. so if in the form where
that function is performed, it returns a value for mv1 and
it's displayed in a textbox, how do i get a textbox on the
next form to recognize mv1??


-----Original Message-----
The error you are getting is because mv1 is a function
that takes a string as an argument and the argument is
declared optional.

I understand the other things you said about returning
values from functions. You will need to clarify what the
problem is.

-----Original Message-----
in my application, i have multiple forms. i have some
function declared as public in my module. now i know that
i can't return a value from a function to any form unless
i create another function in the module that sets another
variable to that value (i.e. if the function is mv1 and i
call it on form1 then for form2 to recognize it i have to
create another function in the module that sets another
variable x=mv1 and then in form2 i refer to x). i've done
this but when i get an error saying "argument is not
optional". i don't know what this means or what i'm doing
wrong....

the first function is as follows:

public function mv1(tbl as string) as double
mv1=DAvg("[field8]", tbl, "[ID]"<60)
end function


then the next one is:

public function setmv1() as double
setmv1=mv1
end function

i get the error on "setmv1=mv1"

any suggestions. thanx in advance.
john
.
.
 
B

Bob Noll

I can't seem to type this morning. The below post should
read:

.... the argument is NOT declared optional.

I DON'T understand the ...
-----Original Message-----
The error you are getting is because mv1 is a function
that takes a string as an argument and the argument is
declared optional.

I understand the other things you said about returning
values from functions. You will need to clarify what the
problem is.

-----Original Message-----
in my application, i have multiple forms. i have some
function declared as public in my module. now i know that
i can't return a value from a function to any form unless
i create another function in the module that sets another
variable to that value (i.e. if the function is mv1 and i
call it on form1 then for form2 to recognize it i have to
create another function in the module that sets another
variable x=mv1 and then in form2 i refer to x). i've done
this but when i get an error saying "argument is not
optional". i don't know what this means or what i'm doing
wrong....

the first function is as follows:

public function mv1(tbl as string) as double
mv1=DAvg("[field8]", tbl, "[ID]"<60)
end function


then the next one is:

public function setmv1() as double
setmv1=mv1
end function

i get the error on "setmv1=mv1"

any suggestions. thanx in advance.
john
.
.
 
J

John G

how do i make it optional??

-----Original Message-----
I can't seem to type this morning. The below post should
read:

.... the argument is NOT declared optional.

I DON'T understand the ...
-----Original Message-----
The error you are getting is because mv1 is a function
that takes a string as an argument and the argument is
declared optional.

I understand the other things you said about returning
values from functions. You will need to clarify what the
problem is.

-----Original Message-----
in my application, i have multiple forms. i have some
function declared as public in my module. now i know that
i can't return a value from a function to any form unless
i create another function in the module that sets another
variable to that value (i.e. if the function is mv1 and i
call it on form1 then for form2 to recognize it i have to
create another function in the module that sets another
variable x=mv1 and then in form2 i refer to x). i've done
this but when i get an error saying "argument is not
optional". i don't know what this means or what i'm doing
wrong....

the first function is as follows:

public function mv1(tbl as string) as double
mv1=DAvg("[field8]", tbl, "[ID]"<60)
end function


then the next one is:

public function setmv1() as double
setmv1=mv1
end function

i get the error on "setmv1=mv1"

any suggestions. thanx in advance.
john
.
.
.
 
M

Marshall Barton

John said:
in my application, i have multiple forms. i have some
function declared as public in my module. now i know that
i can't return a value from a function to any form unless
i create another function in the module that sets another
variable to that value (i.e. if the function is mv1 and i
call it on form1 then for form2 to recognize it i have to
create another function in the module that sets another
variable x=mv1 and then in form2 i refer to x). i've done
this but when i get an error saying "argument is not
optional". i don't know what this means or what i'm doing
wrong....

the first function is as follows:

public function mv1(tbl as string) as double
mv1=DAvg("[field8]", tbl, "[ID]"<60)
end function


then the next one is:

public function setmv1() as double
setmv1=mv1
end function

i get the error on "setmv1=mv1"

You didn't tell the function what table to use. That line
will have to be something like:

setmv1 = mv1("sometablename")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top