Error in function

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

Guest

Would you be able to help me with my new problem?......

I get another run time error '13': type mismatch
It is highlighting this line of my IsRange function - IsRange = "1-2"
The whole function is below. I'm not sure where to go with this error.

Public Function IsRange(ByVal lngNum As Long) As Boolean

Select Case lngNum
Case 33 To 50
IsRange = "33-50"
Case 51 To 100
IsRange = "51-100"
Case 11 To 12
IsRange = "11-12"
Case 13 To 15
IsRange = "13-15"
Case 16 To 17
IsRange = "16-17"
Case 18 To 21
IsRange = "18-21"
Case 22 To 26
IsRange = "22-26"
Case 27 To 32
IsRange = "27-32"
Case 101 To 250
IsRange = "101-250"
Case Is > 250
IsRange = "GT 250"
Case 10 To 10
IsRange = "10"
Case 9 To 9
IsRange = "9"
Case 8 To 8
IsRange = "8"
Case 7 To 7
IsRange = "7"
Case 6 To 6
IsRange = "6"
Case 5 To 5
IsRange = "5"
Case 4 To 4
IsRange = "4"
Case 3 To 3
IsRange = "3"
Case 1 To 2
IsRange = "1-2"
Case 0 To 0
IsRange = "0"

End Select

End Function
 
You have defined IsRange as Boolean in your function, and are then
attempting to assign string values to it. Try:

Public Function IsRange(ByVal lngNum As Long) As String

HTH,

Rob
 
I have changed Boolean to String in that function. This function is called
on by another function, that is now giving me a run time error '13': type
mismatch. The debugger is highlighting this: IsRangeAll = IsRange(INVOICES)
in the function below: I appreciate any help you can provide.

Public Function IsRangeAll(ByVal INVOICES As Long, ByVal BrnType As String,
ByVal BOD_CODE As String) As Boolean
Select Case BrnType & Left$(BOD_CODE, 1)
Case "FR"
IsRangeAll = IsRangeSF(INVOICES)
Case "FN"
IsRangeAll = IsRangeLS(INVOICES)
Case "BR"
IsRangeAll = IsRange(INVOICES)
Case "BN"
IsRangeAll = IsRangeLS(INVOICES)
Case Else
MsgBox "cannot determine IsRangeall"
IsRangeAll = False
End Select
End Function
 
Now you have declared Israngeall as Boolean, and you are still trying to
assign a string to it.

Are you trying to get IsRangeAll to return TRUE / FALSE ?

If so, give an example condition.
 
There in lies my inexperience, I guess. No I am not trying to return TRUE /
FALSE, I just don't know what I'm doing. :) I originally has everything as
String and that didn't work. Someone suggested that I have the functions as
Boolean. I have 3 fields in a query that are being looked at to assign a
specific value to based on the 3 functions, IsRangeSF, IsRangeLS, and
IsRange.
 
We are getting closer.

You should declare the Function AS whatever type you are trying to return.
STRING looks about right, and I would expect you function to do something,
which may even be right, if you make that change. Given your state of
confusion, you may have to change IsRangeSF etc too. Count the bruises,
count the lessons.

A function behaves as though it is a variable of the type that you assign
to it, although it can change the parameters passed to it if you so desire
(not generally a good idea.)

Inside the function IsRangeall you set IsRangeAll as though it were a
variable, outside IsRangeAll you use IsRangeAll(...) as though it was a read
only variable.

Start a new thread if you have any further questions.
 
I will start a new thread like you mentioned. I changed my function(s) so
they all return as String and I get a message that says "Cannot determine
IsRangeAll"
 
That comes from :
MsgBox "cannot determine IsRangeall"

Which is the else condition in:
Select Case BrnType & Left$(BOD_CODE, 1)

So lets try: changing the msgbox to:

MsgBox "cannot determine IsRangeall, code = " & BrnType & Left$(BOD_CODE, 1)
 
Alright, that gives me a new message box that says "cannot determine
IsRangeAllBS". Then when I enter through about 100 of these messages the
debugger takes me to a line in the IsRangeLS function...it highlights the
first line of the code:

Public Function IsRangeLS(ByVal lngNum As Long) As String

Select Case lngNum
Case 31 To 50
IsRange = "31-50"
Case 51 To 100
IsRange = "51-100"
Case 11 To 30
IsRange = "11-30"
Case 101 To 250
IsRange = "101-250"
Case Is > 250
IsRange = "GT 250"
Case 9 To 10
IsRange = "9-10"
Case 7 To 8
IsRange = "7-8"
Case 5 To 6
IsRange = "5-6"
Case 1 To 4
IsRange = "1-4"
Case 0 To 0
IsRange = "0"

End Select

End Function
Is there any way that instead of the message box, I can just have False or
an N/A or something returned? All of the records will not be able to fit the
variable requirements, so those records I would just like to have that field
blank or N/A or something like that.
 
You posted code from IsRaneAll::

you can just remove the message box, one problem solved. If you are seeting
a field to IsRangeAll then:

Case else
IsRangeAll = ""
End Select
 
OK, I did that and took out the message box.

I now get this: "Compile error: Function call on left-hand side of
assignment must return Variant or Object"
The first line of code in the following function is highlighted within the
debugger:

[color:red] Public Function IsRangeLS(ByVal lngNum As Long) As String
[/QUOTE]

Select Case lngNum
Case 31 To 50
IsRange = "31-50"
Case 51 To 100
IsRange = "51-100"
Case 11 To 30
IsRange = "11-30"
Case 101 To 250
IsRange = "101-250"
Case Is > 250
IsRange = "GT 250"
Case 9 To 10
IsRange = "9-10"
Case 7 To 8
IsRange = "7-8"
Case 5 To 6
IsRange = "5-6"
Case 1 To 4
IsRange = "1-4"
Case 0 To 0
IsRange = "0"

End Select

End Function
 
I finally figured it out!!

I had to change all of my case lines for the IsRangeLS function to look like:

IsRangeLS = "31-50" instead of

IsRange = "31-50"

Thank you so much for the help getting me to the bottom of this issue. It
has been "bugging" me for weeks!!!!!


Lucien said:
OK, I did that and took out the message box.

I now get this: "Compile error: Function call on left-hand side of
assignment must return Variant or Object"
The first line of code in the following function is highlighted within the
debugger:

[color:red] Public Function IsRangeLS(ByVal lngNum As Long) As String

Select Case lngNum
Case 31 To 50
IsRange = "31-50"
Case 51 To 100
IsRange = "51-100"
Case 11 To 30
IsRange = "11-30"
Case 101 To 250
IsRange = "101-250"
Case Is > 250
IsRange = "GT 250"
Case 9 To 10
IsRange = "9-10"
Case 7 To 8
IsRange = "7-8"
Case 5 To 6
IsRange = "5-6"
Case 1 To 4
IsRange = "1-4"
Case 0 To 0
IsRange = "0"

End Select

End Function


David F Cox said:
You posted code from IsRaneAll::


you can just remove the message box, one problem solved. If you are seeting
a field to IsRangeAll then:

Case else
IsRangeAll = ""
End Select
[/QUOTE]
 
Oh dear, you really have not got your head around Function procedures. I
will explain the bits you know as well as the bits you are muddled about.

The function you have here is called ISRangeLS

It is defined AS string

It will be used as though it were a String variable something like so:

MyString = IsRangeLS(MyNumber) ' MyNumber is the input variable.

In order for this to work somehow VBA must know what value you want
IsRangeLS to return.

This is done witing the IsRangeLS function code by assigning IsRangeLS to a
value, Like so:

IsRangeLS = "1-4"

Instead of doing that you have written:

IsRange = "1-4" 'and similar assignments

The only place such an assignment is vaild is within the IsRange Function.,
and you are inside the IsRangeLS function instead.

That should be enough information for you to correct your code. I suspect
that you have made similar mistakes elsewhere of the same nature. You should
be able to fix all of those.

Good Luck



somewhere within it
Lucien said:
OK, I did that and took out the message box.

I now get this: "Compile error: Function call on left-hand side of
assignment must return Variant or Object"
The first line of code in the following function is highlighted within the
debugger:

[color:red] Public Function IsRangeLS(ByVal lngNum As Long) As String

Select Case lngNum
Case 31 To 50
IsRange = "31-50"
Case 51 To 100
IsRange = "51-100"
Case 11 To 30
IsRange = "11-30"
Case 101 To 250
IsRange = "101-250"
Case Is > 250
IsRange = "GT 250"
Case 9 To 10
IsRange = "9-10"
Case 7 To 8
IsRange = "7-8"
Case 5 To 6
IsRange = "5-6"
Case 1 To 4
IsRange = "1-4"
Case 0 To 0
IsRange = "0"

End Select

End Function


David F Cox said:
You posted code from IsRaneAll::


you can just remove the message box, one problem solved. If you are
seeting
a field to IsRangeAll then:

Case else
IsRangeAll = ""
End Select
[/QUOTE]
 
You are right, I did have more errors of this type...and it is absolutely due
to my lack of understanding. I really appreciate your help and patience and
your explanation made the dots actually connect! Some of your peers are not
as patient with people like myself, who are trying to self teach our way
through Access.

Thanks again!!


David F Cox said:
Oh dear, you really have not got your head around Function procedures. I
will explain the bits you know as well as the bits you are muddled about.

The function you have here is called ISRangeLS

It is defined AS string

It will be used as though it were a String variable something like so:

MyString = IsRangeLS(MyNumber) ' MyNumber is the input variable.

In order for this to work somehow VBA must know what value you want
IsRangeLS to return.

This is done witing the IsRangeLS function code by assigning IsRangeLS to a
value, Like so:

IsRangeLS = "1-4"

Instead of doing that you have written:

IsRange = "1-4" 'and similar assignments

The only place such an assignment is vaild is within the IsRange Function.,
and you are inside the IsRangeLS function instead.

That should be enough information for you to correct your code. I suspect
that you have made similar mistakes elsewhere of the same nature. You should
be able to fix all of those.

Good Luck



somewhere within it
Lucien said:
OK, I did that and took out the message box.

I now get this: "Compile error: Function call on left-hand side of
assignment must return Variant or Object"
The first line of code in the following function is highlighted within the
debugger:

[color:red] Public Function IsRangeLS(ByVal lngNum As Long) As String

Select Case lngNum
Case 31 To 50
IsRange = "31-50"
Case 51 To 100
IsRange = "51-100"
Case 11 To 30
IsRange = "11-30"
Case 101 To 250
IsRange = "101-250"
Case Is > 250
IsRange = "GT 250"
Case 9 To 10
IsRange = "9-10"
Case 7 To 8
IsRange = "7-8"
Case 5 To 6
IsRange = "5-6"
Case 1 To 4
IsRange = "1-4"
Case 0 To 0
IsRange = "0"

End Select

End Function


David F Cox said:
You posted code from IsRaneAll::

Case Else
MsgBox "cannot determine IsRangeall"
IsRangeAll = False
End Select

you can just remove the message box, one problem solved. If you are
seeting
a field to IsRangeAll then:

Case else
IsRangeAll = ""
End Select


Alright, that gives me a new message box that says "cannot determine
IsRangeAllBS". Then when I enter through about 100 of these messages
the
debugger takes me to a line in the IsRangeLS function...it highlights
the
first line of the code:

Public Function IsRangeLS(ByVal lngNum As Long) As String

Select Case lngNum
Case 31 To 50
IsRange = "31-50"
Case 51 To 100
IsRange = "51-100"
Case 11 To 30
IsRange = "11-30"
Case 101 To 250
IsRange = "101-250"
Case Is > 250
IsRange = "GT 250"
Case 9 To 10
IsRange = "9-10"
Case 7 To 8
IsRange = "7-8"
Case 5 To 6
IsRange = "5-6"
Case 1 To 4
IsRange = "1-4"
Case 0 To 0
IsRange = "0"

End Select

End Function
Is there any way that instead of the message box, I can just have False
or
an N/A or something returned? All of the records will not be able to
fit
the
variable requirements, so those records I would just like to have that
field
blank or N/A or something like that.

:

That comes from :

MsgBox "cannot determine IsRangeall"

Which is the else condition in:

Select Case BrnType & Left$(BOD_CODE, 1)

So lets try: changing the msgbox to:

MsgBox "cannot determine IsRangeall, code = " & BrnType &
Left$(BOD_CODE,
1)



I will start a new thread like you mentioned. I changed my
function(s)
so
they all return as String and I get a message that says "Cannot
determine
IsRangeAll"


:

We are getting closer.

You should declare the Function AS whatever type you are trying to
return.
STRING looks about right, and I would expect you function to do
something,
which may even be right, if you make that change. Given your state
of
confusion, you may have to change IsRangeSF etc too. Count the
bruises,
count the lessons.

A function behaves as though it is a variable of the type that you
assign
to it, although it can change the parameters passed to it if you so
desire
(not generally a good idea.)

Inside the function IsRangeall you set IsRangeAll as though it were
a
variable, outside IsRangeAll you use IsRangeAll(...) as though it
was
a
read
only variable.

Start a new thread if you have any further questions.

There in lies my inexperience, I guess. No I am not trying to
return
TRUE
/
FALSE, I just don't know what I'm doing. :) I originally has
everything
as
String and that didn't work. Someone suggested that I have the
functions
as
Boolean. I have 3 fields in a query that are being looked at to
assign
a
specific value to based on the 3 functions, IsRangeSF, IsRangeLS,
and
IsRange.


:

Now you have declared Israngeall as Boolean, and you are still
trying
to
assign a string to it.

Are you trying to get IsRangeAll to return TRUE / FALSE ?

If so, give an example condition.




I have changed Boolean to String in that function. This
function
is
called
on by another function, that is now giving me a run time error
'13':
type
mismatch. The debugger is highlighting this: IsRangeAll =
IsRange(INVOICES)
in the function below: I appreciate any help you can provide.

Public Function IsRangeAll(ByVal INVOICES As Long, ByVal
BrnType
As
String,
ByVal BOD_CODE As String) As Boolean
Select Case BrnType & Left$(BOD_CODE, 1)
Case "FR"
IsRangeAll = IsRangeSF(INVOICES)
Case "FN"
IsRangeAll = IsRangeLS(INVOICES)
Case "BR"
IsRangeAll = IsRange(INVOICES)
Case "BN"
IsRangeAll = IsRangeLS(INVOICES)
Case Else
MsgBox "cannot determine IsRangeall"
IsRangeAll = False
End Select
End Function

:

You have defined IsRange as Boolean in your function, and are
then
attempting to assign string values to it. Try:

Public Function IsRange(ByVal lngNum As Long) As String

HTH,

Rob

Would you be able to help me with my new problem?......

I get another run time error '13': type mismatch
It is highlighting this line of my IsRange function -
IsRange
=
"1-2"
The whole function is below. I'm not sure where to go with
this
error.

Public Function IsRange(ByVal lngNum As Long) As Boolean

Select Case lngNum
Case 33 To 50
IsRange = "33-50"
Case 51 To 100
IsRange = "51-100"
Case 11 To 12
IsRange = "11-12"
Case 13 To 15
IsRange = "13-15"
Case 16 To 17
IsRange = "16-17"
[/QUOTE]
 
Back
Top