Enter value in control

MvP14

Registered User.
Local time
Today, 17:01
Joined
Apr 15, 2003
Messages
66
I have the following code:

For i = 0 To conMaxControls - 1
If f.Controls("cbxFld" & i).Enabled = True Then
If f.Controls("cbxFld" & i).Value = strcbxFld Then
f.Controls("txtVal" & i) = strKeyword
f.Controls("txtVal" & i).SetFocus
End If
End If
Next i

strcbxFld is a string earlier defined, and so is strKeyword.

The code works.

However, because the value of several cbxFld may be strcbxFld, running the code has the effect that for each i where cbxFldi is strcbxFld, the value of txtVali is set to strKeyword.

What I've been trying to do is to change the code in such a way that the value of txtVali is only set to strKeyword if txtVali is null.

But none of my attempts have been succesful up until now. Can anyone help me out?
 
For i = 0 To conMaxControls - 1
If f.Controls("cbxFld" & i).Enabled = True Then
If f.Controls("cbxFld" & i).Value = strcbxFld Then
If not isnull (f.Controls("txtVal" & i)) then 'if 3
f.Controls("txtVal" & i) = strKeyword
f.Controls("txtVal" & i).SetFocus
end if 'If 3
End If
End If
Next i

You could simplify this to

For i = 0 To conMaxControls - 1
If f.Controls("cbxFld" & i).Enabled = True and f.Controls("cbxFld" & i).Value = strcbxFld and not isnull (f.Controls("txtVal" & i)) then
f.Controls("txtVal" & i) = strKeyword
f.Controls("txtVal" & i).SetFocus
End If
Next i
 
thanks

Thank you. It works the way I want it to now.
 

Users who are viewing this thread

Back
Top Bottom