Trying to use a function to fill a text box

rap1971

Registered User.
Local time
Today, 17:26
Joined
Jan 16, 2001
Messages
23
I have two text boxes...T1 and T2...I am trying to send the contents of these text boxes to a function CostFactor and return a value into T3. The function is declared and coded in a module in the same database. The code compiles and appears to be correct.
I set the control source of T3
=CostFactor([T1],[T2]). When I run the form I get ?#Name in the T3 text box...

What am I doing wrong???
 
Are your names for T1 and T2 exactly correct? Access is pretty funny about that.
 
The names aren't T1 and T2...they are txtcoolingcap and txtheatgain respectively. But I'm spelling them correctly, if that's what you mean.

ugh.
 
Have you stepped through the code to see the values of your variables as your program functions?

Put a breakpoint on your function call, and see if you can't solve the problem there. It seems to me that your function may not be returning a value to the text box.

provide a sample of the function call and skeleton, and we'll see if it works.

Duane Barker
 
How do I step through the code of just that module...the only thing I see is a Compile Cooling Cost (the name of my db) in the DeBug list.

I watered down my code...you'll get the idea...

T1 is actually named txtheatgain and is entered by the user Format: general number

T2 is txtcoolingcap and is received from an AfterUpdate Event in a combo box. It is a column in the combo box that is assigned to txtcoolingcap once a selection is made. Format: general number

T3 is txtcostfactor and has control source
=CostFactor([txtcoolingcap],[txtheatgain])

The function CostFactor is declared in the CostFactor module with this code...


Function CostFactor(lngCoolingCapacity As Long, lngHeatGain As Long) As Double

Dim intcooling As Integer
Dim inthtgn As Integer
Dim CstFact(2,2) As Double

/*Then I populate the Array Like This*/
CstFact(0,0) = 1.00
CstFact(0,1) = 1.14
CstFact(0,2) = 1.29

/*I've never done an array in VB before...only in C...would love to know if there's a better way to fill a multidimensional array without assigning each one individually*/

/*This next part is watered down...I hard-coded figures for examples' sake...*/

Select Case lngCoolingCapacity
Case lngCoolingCapacity = 18000
intcooling = 0
Case Else
intcooling = 1
End Select

Select Case lngHeatGain
Case lngHeatGain = 22400
inthtgn = 2
Case Else
inthtgn = 0
End Select

CostFactor = CstFact(intcooling,inthtgn)
End Function

If you can muddle through that and give any advice I would love any and all input. I'm a C programmer by nature and VB is pretty close.
I'm trying.
Help.
Rebecca
 
I will muddle through the code tonight.

To set a breakpoint, click to the left of the line where you want it to stop. A red dot will appear beside the code. When you run the code, it will stop when it reaches the red dot.

Duane Barker
 
The problem appears to be in my array, not in the function handling.

I also altered my Select Case structure...I found some different syntax and fixed that.

So I guess don't beat your head against a wall...it's in the array.

If you know anything about that please let me know.

Thanks
R
 
I've got it...
The syntax problem was in my Select Case statement
AND
I inadvertantly named my module AND my function CostFactor. Access didn't quite know what to do with that.

Rebecca
 

Users who are viewing this thread

Back
Top Bottom