Error-Expected line number or label or statement or end of stateme

G

Guest

I'm trying to create a module that will take a single character code and
return the word it represents. I was using an If statement in 2 reports that
did this fine. I have to create more reports that will use this so I decided
to put the If statement in a function and then use the function in all the
reports. However, I get a compile error when I type in the line to 'call' the
function.
This is the If that was working:

If AnimalType = "D" Then
[TypeOf] = "Dog"
ElseIf AnimalType = "C" Then
[TypeOf] = "Cat"
Else
[TypeOf] = "Other"
End
End If
This above works fine. The AnimalType is from the table and the TypeOf is an
unbound field used do print the word on the report.

This is the function:
Public Function TypeAnimal(TypeOfAnimal As String) As String

If TypeOfAnimal = "D" Then
[TypeAnimal] = "Dog"
ElseIf TypeOfAnimal = "C" Then
[TypeAnimal] = "Cat"
Else
[TypeAnimal] = "Other"
End If
End Function

This is the 'call' statement on the Click Event:
TypeOf = TypeAnimal(AnimalType)

*TypeOf is the unbound field on the report that prints the word returned.*
*AnimalType is from the Animal Table*

Error message:
Expected:line number or label or statement or end of statement

Does anyone have any ideas about what's causing this?

Thanks,
RandyM
 
J

John Spencer

First, try removing the brackets around the function name.

Public Function TypeAnimal(TypeOfAnimal As String) As String

If TypeOfAnimal = "D" Then
TypeAnimal= "Dog"
ElseIf TypeOfAnimal = "C" Then
TypeAnimal = "Cat"
Else
TypeAnimal = "Other"
End If

End Function
 
G

Guest

John,
Thanks for answering. I tried removing the brackets, but now the line that
calls the function from an event subroutine turns red when I press enter. The
line is

TypeOf = TypeAnimal(AnimalType).

I don't understand why this doesn't work. I had another IF statement I was
using that merged the First and Last names into one name, I turned it into a
function and it works fine. I've compared them and I can't see what I've done
differently between the two. This seems like a straight forward process, but
somehow I'm managing to screw it up. Any ideas?

Thanks,
RandyM

John Spencer said:
First, try removing the brackets around the function name.

Public Function TypeAnimal(TypeOfAnimal As String) As String

If TypeOfAnimal = "D" Then
TypeAnimal= "Dog"
ElseIf TypeOfAnimal = "C" Then
TypeAnimal = "Cat"
Else
TypeAnimal = "Other"
End If

End Function

WCDoan said:
I'm trying to create a module that will take a single character code and
return the word it represents. I was using an If statement in 2 reports
that
did this fine. I have to create more reports that will use this so I
decided
to put the If statement in a function and then use the function in all the
reports. However, I get a compile error when I type in the line to 'call'
the
function.
This is the If that was working:

If AnimalType = "D" Then
[TypeOf] = "Dog"
ElseIf AnimalType = "C" Then
[TypeOf] = "Cat"
Else
[TypeOf] = "Other"
End
End If
This above works fine. The AnimalType is from the table and the TypeOf is
an
unbound field used do print the word on the report.

This is the function:
Public Function TypeAnimal(TypeOfAnimal As String) As String

If TypeOfAnimal = "D" Then
[TypeAnimal] = "Dog"
ElseIf TypeOfAnimal = "C" Then
[TypeAnimal] = "Cat"
Else
[TypeAnimal] = "Other"
End If
End Function

This is the 'call' statement on the Click Event:
TypeOf = TypeAnimal(AnimalType)

*TypeOf is the unbound field on the report that prints the word returned.*
*AnimalType is from the Animal Table*

Error message:
Expected:line number or label or statement or end of statement

Does anyone have any ideas about what's causing this?

Thanks,
RandyM
 
J

John Spencer

I just tested the function in the immediate window and it works for me.

Perhaps TypeOf is the problem.

If the function is in a vba module, then try typing the following in the
immediate window and see if it works

?TypeAnimal("C")
Cat

If that works, then you need to look at TypeOf - I have a vague feeling
that TypeOf might be a reserved word. Try changing that to TxtTypeOf =
TypeAnimal(AnimalType)

See if that works.


WCDoan said:
John,
Thanks for answering. I tried removing the brackets, but now the line
that
calls the function from an event subroutine turns red when I press enter.
The
line is

TypeOf = TypeAnimal(AnimalType).

I don't understand why this doesn't work. I had another IF statement I was
using that merged the First and Last names into one name, I turned it into
a
function and it works fine. I've compared them and I can't see what I've
done
differently between the two. This seems like a straight forward process,
but
somehow I'm managing to screw it up. Any ideas?

Thanks,
RandyM

John Spencer said:
First, try removing the brackets around the function name.

Public Function TypeAnimal(TypeOfAnimal As String) As String

If TypeOfAnimal = "D" Then
TypeAnimal= "Dog"
ElseIf TypeOfAnimal = "C" Then
TypeAnimal = "Cat"
Else
TypeAnimal = "Other"
End If

End Function

WCDoan said:
I'm trying to create a module that will take a single character code
and
return the word it represents. I was using an If statement in 2 reports
that
did this fine. I have to create more reports that will use this so I
decided
to put the If statement in a function and then use the function in all
the
reports. However, I get a compile error when I type in the line to
'call'
the
function.
This is the If that was working:

If AnimalType = "D" Then
[TypeOf] = "Dog"
ElseIf AnimalType = "C" Then
[TypeOf] = "Cat"
Else
[TypeOf] = "Other"
End
End If
This above works fine. The AnimalType is from the table and the TypeOf
is
an
unbound field used do print the word on the report.

This is the function:
Public Function TypeAnimal(TypeOfAnimal As String) As String

If TypeOfAnimal = "D" Then
[TypeAnimal] = "Dog"
ElseIf TypeOfAnimal = "C" Then
[TypeAnimal] = "Cat"
Else
[TypeAnimal] = "Other"
End If
End Function

This is the 'call' statement on the Click Event:
TypeOf = TypeAnimal(AnimalType)

*TypeOf is the unbound field on the report that prints the word
returned.*
*AnimalType is from the Animal Table*

Error message:
Expected:line number or label or statement or end of statement

Does anyone have any ideas about what's causing this?

Thanks,
RandyM
 
G

Guest

John,
Thank you, thank you, thank you. That did it. I changed the name and it
works like a charm. Thanks for taking time to help...I appreciate it. Have a
great weekend.

Thanks again,
RandyM

John Spencer said:
I just tested the function in the immediate window and it works for me.

Perhaps TypeOf is the problem.

If the function is in a vba module, then try typing the following in the
immediate window and see if it works

?TypeAnimal("C")
Cat

If that works, then you need to look at TypeOf - I have a vague feeling
that TypeOf might be a reserved word. Try changing that to TxtTypeOf =
TypeAnimal(AnimalType)

See if that works.


WCDoan said:
John,
Thanks for answering. I tried removing the brackets, but now the line
that
calls the function from an event subroutine turns red when I press enter.
The
line is

TypeOf = TypeAnimal(AnimalType).

I don't understand why this doesn't work. I had another IF statement I was
using that merged the First and Last names into one name, I turned it into
a
function and it works fine. I've compared them and I can't see what I've
done
differently between the two. This seems like a straight forward process,
but
somehow I'm managing to screw it up. Any ideas?

Thanks,
RandyM

John Spencer said:
First, try removing the brackets around the function name.

Public Function TypeAnimal(TypeOfAnimal As String) As String

If TypeOfAnimal = "D" Then
TypeAnimal= "Dog"
ElseIf TypeOfAnimal = "C" Then
TypeAnimal = "Cat"
Else
TypeAnimal = "Other"
End If

End Function

I'm trying to create a module that will take a single character code
and
return the word it represents. I was using an If statement in 2 reports
that
did this fine. I have to create more reports that will use this so I
decided
to put the If statement in a function and then use the function in all
the
reports. However, I get a compile error when I type in the line to
'call'
the
function.
This is the If that was working:

If AnimalType = "D" Then
[TypeOf] = "Dog"
ElseIf AnimalType = "C" Then
[TypeOf] = "Cat"
Else
[TypeOf] = "Other"
End
End If
This above works fine. The AnimalType is from the table and the TypeOf
is
an
unbound field used do print the word on the report.

This is the function:
Public Function TypeAnimal(TypeOfAnimal As String) As String

If TypeOfAnimal = "D" Then
[TypeAnimal] = "Dog"
ElseIf TypeOfAnimal = "C" Then
[TypeAnimal] = "Cat"
Else
[TypeAnimal] = "Other"
End If
End Function

This is the 'call' statement on the Click Event:
TypeOf = TypeAnimal(AnimalType)

*TypeOf is the unbound field on the report that prints the word
returned.*
*AnimalType is from the Animal Table*

Error message:
Expected:line number or label or statement or end of statement

Does anyone have any ideas about what's causing this?

Thanks,
RandyM
 

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