VB woes

  • Thread starter Thread starter xargon
  • Start date Start date
X

xargon

Hi everyone,

I am trying to use some VB code behind an Access form. I am developing
gray hairs here because of an error and am wondering if someone can
throw some light on it.

I have a text box control and when I click a button I want to get the
value in the text box control:

So, I have something like:

If Trim(DataSetID.Value) Is Nothing Then

I get the following run time error:

You can't reference the property or method for a control unless the
control has the focus.

This is bizarre! Why can I not get the value unles sit has focus!!

Please help!
xarg
 
Xarg,

I am not 100% sure what you are driving at here, but does this do it?...
If IsNull(Me.DataSetID) Then
 
My bet is, you are referencing the .Text property of the control - not
the .Value property.

You can not reference the .Text property unless the control has the
focus. And if you've just clicked a button, the textbox doesn't have
the focus then.

HTH,
TC [MVP Access]
 
xargon said:
Hi everyone,

I am trying to use some VB code behind an Access form. I am developing
gray hairs here because of an error and am wondering if someone can
throw some light on it.

I have a text box control and when I click a button I want to get the
value in the text box control:

So, I have something like:

If Trim(DataSetID.Value) Is Nothing Then

I get the following run time error:

You can't reference the property or method for a control unless the
control has the focus.

This is bizarre! Why can I not get the value unles sit has focus!!

Are you sure you aren't trying to get the Text property of the control?
That's the one you can't get unless it has the focus. The Value
property should be available at all times.

Aside from that, you shouldn't be testing the Value property with Is
Nothing -- that's for objects, not for values. Use IsNull(), as Steve
Schapel pointed out.
 
Back
Top