Compile error

  • Thread starter DMUM via AccessMonster.com
  • Start date
D

DMUM via AccessMonster.com

Hello

I just recently took over a database to add some reporting capabilities. As
I usually do when adding code, I tried to compile it. I keep getting this
error:

"Function call on left-hand side of assignment must returnVariant or object"

This is the Function it is referring to:

Public Function getDistrictCode() As String

On Error GoTo Err_getDistrictCode

getUnionCode = STR_DISTRICT_CODE
GoTo Exit_getDistrictCode

Exit_getDistrictCode:
Exit Function

Err_getDistrictCode:
Resume Exit_getDistrictCode

End Function

I changed it to a variant and then also changed STR_DISTRICT_CODE to a
variant but I still get the same error.

STR_DISTRICT_CODE is tied to another variable - .cboDistrictCode1 which is
populated by a VBA SQL query.

The query is pulling the data from a table which contains "TEXT" fields.

I have 2 questions:

1. How/why is the code working if it won't compile?
2. How do I fix this so the code will compile?

Thank you
 
J

John Vinson

Hello

I just recently took over a database to add some reporting capabilities. As
I usually do when adding code, I tried to compile it. I keep getting this
error:

"Function call on left-hand side of assignment must returnVariant or object"

This is the Function it is referring to:

Public Function getDistrictCode() As String

On Error GoTo Err_getDistrictCode

getUnionCode = STR_DISTRICT_CODE

This is apparently the error. You've named your function
getDistrictCode but you're setting the value of getUnionCode; and
nowhere in your function do you set the value of getDistrictCode.
GoTo Exit_getDistrictCode

Exit_getDistrictCode:
Exit Function

Err_getDistrictCode:
Resume Exit_getDistrictCode

End Function

I changed it to a variant and then also changed STR_DISTRICT_CODE to a
variant but I still get the same error.

STR_DISTRICT_CODE is tied to another variable - .cboDistrictCode1 which is
populated by a VBA SQL query.

If it's not a Global (or Public, depending on your version) variable,
this function won't know anything about it at all. If you're getting
it from a combo box, just leave out the middleman - use

getDistrictCode = Forms!YourFormName!cboDistrictCode1


John W. Vinson[MVP]
 

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