Type conversion error on select/update/make table query (1 Viewer)

PISI Guy

New member
Local time
Today, 12:56
Joined
Dec 8, 2011
Messages
8
I've written a function that takes three integers and returns a double. Any time I try to call it from a query it returns an error; select query will return #error, update or make table return a type conversion failure. ??

1) The code works fine when run in the immediate window of VBA editor
2) I'm sure that the values I'm passing it are of the correct type (integer)
3) I've tried update queries where the field for the calculated value is double (what it should be), variant, and text; all give type conversion error
4) When I first tested the code it worked fine, except that certain calls resulted in division by zero. I changed one line of arithmatic code, now I'm having this problem

Code:
Function plot_live_C(intInst As Integer, intPlot As Integer, intMeas As Integer) As Double
 
'some stuff happens in here, works great in VBA editor
 
plot_live_c=dblTotalC
 
exit function

sample SQL select query is
Code:
 SELECT tMeasurement_Dates.installation, tMeasurement_Dates.plot, tMeasurement_Dates.measurement, plot_live_C([tMeasurement_Dates]![installation]),([tMeasurement_Dates]![plot],[tMeasurement_Dates]![measurement]) AS liveC
FROM tMeasurement_Dates;

Thanks for any help, I'm baffled!
 

spikepl

Eledittingent Beliped
Local time
Today, 22:56
Joined
Nov 3, 2010
Messages
6,142
and you have valid not-null input data in all the records?
 

PISI Guy

New member
Local time
Today, 12:56
Joined
Dec 8, 2011
Messages
8
Yup, all that's handled in the table definition. In addition I've tried it selecting for a single record with known (valid) values. I also tried just passing values directly in the query e.g. plot_live_C(1,1010,1) and had the same problem. There must be something I'm missing...
 

spikepl

Eledittingent Beliped
Local time
Today, 22:56
Joined
Nov 3, 2010
Messages
6,142
Weird. Try to wrap the call in Cdbl

Cdbl(Yourfunction)
 

spikepl

Eledittingent Beliped
Local time
Today, 22:56
Joined
Nov 3, 2010
Messages
6,142
Ah - your function should be Public in a code module -the default is Private
 
Last edited:

PISI Guy

New member
Local time
Today, 12:56
Joined
Dec 8, 2011
Messages
8
Sadly, still #error. I tried some other similar queries as well and I have the same result. The other thing is that the result comes back almost instantly, when actually running the query for the full recordset should take a fair amount of time - a few minutes at least. This makes me think it's a problem with the query call, not the code, and not the handling of the returned value. There are also a few debug.prints in the code, and they do not output to the immediate window when I call the function from a query, again making me think that the code never executes.
 

PISI Guy

New member
Local time
Today, 12:56
Joined
Dec 8, 2011
Messages
8
Bingo. I knew it had to be something simple. Thanks!!
 

Users who are viewing this thread

Top Bottom