Why this code won't work

S

shiro

Private Sub Form_Current()

If [Free air current lo limit_1].Value > 0 And _
[Free air current hi limit_1].Value = 0 Then
[SpecCurr1].ControlSource = "[Free air current lo limit_1]"
End If

End Sub

The field SpecCurr1 won't have any value ( blank ) .Why?
Compiled and got no Compile error.Tried changing SpecCurr1
name to A on VBA window only,VBA should tell me that it can't
find the field A,right? But in this case,VBA doesn't tell anything.Why?

Tried also to remove the bracket and rename by using underscore,but
return me to nut again.
 
J

Jeff Boyce

What are the values of each of the three fields as this code executes?
Insert a STOP above the code, step through it, and use the Immediate window
to discover what values are being used.

To check the logic of your statement (as opposed to the data it uses when
run), try substituting test values for the variables.

--
Regards

Jeff Boyce
www.InformationFutures.net

Microsoft Office/Access MVP


Microsoft IT Academy Program Mentor
http://microsoftitacademy.com/
 
E

Ed Robichaud

Try Me![SpecCurr1] when referring to controls on your form, and/or rename
them to something other than the bound field name, such as "txtSpecCurr1".
 
E

Ed Robichaud

BTW, will this condition ever be met? It appears that you expect the low
limit to be higher than the high limit. What happens in the other
conditions: lo<hi or lo=hi?


Ed Robichaud said:
Try Me![SpecCurr1] when referring to controls on your form, and/or rename
them to something other than the bound field name, such as "txtSpecCurr1".



shiro said:
Private Sub Form_Current()

If [Free air current lo limit_1].Value > 0 And _
[Free air current hi limit_1].Value = 0 Then
[SpecCurr1].ControlSource = "[Free air current lo limit_1]"
End If

End Sub

The field SpecCurr1 won't have any value ( blank ) .Why?
Compiled and got no Compile error.Tried changing SpecCurr1
name to A on VBA window only,VBA should tell me that it can't
find the field A,right? But in this case,VBA doesn't tell anything.Why?

Tried also to remove the bracket and rename by using underscore,but
return me to nut again.
 
L

Linq Adams via AccessMonster.com

I don't see the logic in changing the ControlSource as you move from record
to record! I think what you're trying to do is change the value of [SpecCurr1]
depending on the values of [Free air current lo limit_1] and [Free air
current hi limit_1]. Try this and see if you get the results you want:

Private Sub Form_Current()

If [Free air current lo limit_1].Value > 0 And _
[Free air current hi limit_1].Value = 0 Then
Me.[SpecCurr1].Value = "[Free air current lo limit_1]"
End If

End Sub

Question: What do you want [SpecCurr1] to display if the conditions aren't
met?
 
J

Jeanette Cunningham

Shiro,
the line
[SpecCurr1].ControlSource = "[Free air current lo limit_1]"
sets the control source of SpecCurr1, not its value
You were telling Access which table field to bind the textbox SpecCurr1 to.

Jeanette Cunningham
 

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

Similar Threads

Dynamic Naming of Form Button 3
Can this QuickSort work? 24
Form_Current Infinite Loop 1
why won't this work 2
why is my form dirty? 6
Compile Error - Don't know WHY? 6
why won't this work??? 8
help with code 14

Top