Diabling a field by checkbox

  • Thread starter Thread starter radink
  • Start date Start date
R

radink

I have a check box and a text box. I want to disable the text box if
the check box is not checked.

Im using:

If Me![MBE].Value = "-1" Then
Me![RegNum].Enabled = True
Else
Me![RegNum].Enabled = False

End If

I put this in both the code for the form current and the check box.
When i switch back to the standard entry view, I get the error:

Run-Time Error 438

Object doesn't support this property or method.

When I debug, the line:

Me![RegNum].Enabled = False

is highlighted.

Im lost as to why it's not working.

Thanks!
 
Try this way:
If Me![MBE] = True Then
Me![RegNum].Enabled = True
Else
Me![RegNum].Enabled = False

End If

Or even this one-liner:
Me![RegNum].Enabled = (Me![MBE] = True)
 
Make sure that RegNum is actually the name of the text box and not the
field. I usually rename my controls just to make sure that there is no
question as to which is which. I name the controls like txtRegNum so I know
that I am getting the text box. Also, when using the Bang (!) character,
the primary (not exclusive) use is to designate a field and not the control.
I use the dot when referring to a control and a bang when referring to a
field.

So I would rewrite your code like this (after changing the control names)
plus this is easier (one line):

Me.txtRegNum.Enabled = Me.txtMBE

Plus in your original code you were checking the checkbox field as a string
"-1" instead of using True or -1 without the quotes.

--

Bob Larson
Access MVP
Access World Forums Administrator
Utter Access VIP
Free Access Resources at http://www.btabdevelopment.com
 
Try this way:
If Me![MBE] = True Then
   Me![RegNum].Enabled = True
Else
    Me![RegNum].Enabled = False

End If

Or even this one-liner:
Me![RegNum].Enabled = (Me![MBE] = True)

--
Bill Mosca, MS Access MVPhttp://www.thatlldoit.comhttp://mvp.suppor...roups.yahoo.com/group/MS_Access_Professionals


I have a check box and a text box. I want to disable the text box if
the check box is not checked.
Im using:
If Me![MBE].Value = "-1" Then
  Me![RegNum].Enabled = True
Else
   Me![RegNum].Enabled = False
I put this in both the code for the form current and the check box.
When i switch back to the standard entry view, I get the error:
Run-Time Error 438
Object doesn't support this property or method.
When I debug, the line:
Me![RegNum].Enabled = False
is highlighted.
Im lost as to why it's not working.


Bill,

BAH!

Thanks for the code. I see what I did wrong. Im using RegNum when the
field is actually called text18. RegNum is the data it's tied to.
Thanks for helping me see my errors!

Thanks
Mark
 
Oops that should be this:

Me.txtRegNum.Enabled = Me.chkMBE

forgot to name the checkbox chkMBE instead of txtMBE....

Bob L

boblarson said:
Make sure that RegNum is actually the name of the text box and not the
field. I usually rename my controls just to make sure that there is no
question as to which is which. I name the controls like txtRegNum so I
know that I am getting the text box. Also, when using the Bang (!)
character, the primary (not exclusive) use is to designate a field and not
the control. I use the dot when referring to a control and a bang when
referring to a field.

So I would rewrite your code like this (after changing the control names)
plus this is easier (one line):

Me.txtRegNum.Enabled = Me.txtMBE

Plus in your original code you were checking the checkbox field as a
string "-1" instead of using True or -1 without the quotes.

--

Bob Larson
Access MVP
Access World Forums Administrator
Utter Access VIP
Free Access Resources at http://www.btabdevelopment.com



radink said:
I have a check box and a text box. I want to disable the text box if
the check box is not checked.

Im using:

If Me![MBE].Value = "-1" Then
Me![RegNum].Enabled = True
Else
Me![RegNum].Enabled = False

End If

I put this in both the code for the form current and the check box.
When i switch back to the standard entry view, I get the error:

Run-Time Error 438

Object doesn't support this property or method.

When I debug, the line:

Me![RegNum].Enabled = False

is highlighted.

Im lost as to why it's not working.

Thanks!
 
Oops that should be this:

Me.txtRegNum.Enabled = Me.chkMBE

forgot to name the checkbox chkMBE instead of txtMBE....

Bob L


Make sure that RegNum is actually the name of the text box and not the
field.  I usually rename my controls just to make sure that there is no
question as to which is which.  I name the controls like txtRegNum soI
know that I am getting the text box.  Also, when using the Bang (!)
character, the primary (not exclusive) use is to designate a field and not
the control. I use the dot when referring to a control and a bang when
referring to a field.
So I would rewrite your code like this (after changing the control names)
plus this is easier (one line):
Me.txtRegNum.Enabled = Me.txtMBE
Plus in your original code you were checking the checkbox field as a
string "-1" instead of using True or -1 without the quotes.

Bob Larson
Access MVP
Access World Forums Administrator
Utter Access VIP
Free Access Resources athttp://www.btabdevelopment.com
radink said:
I have a check box and a text box. I want to disable the text box if
the check box is not checked.
Im using:
If Me![MBE].Value = "-1" Then
  Me![RegNum].Enabled = True
Else
   Me![RegNum].Enabled = False
End If
I put this in both the code for the form current and the check box.
When i switch back to the standard entry view, I get the error:
Run-Time Error 438
Object doesn't support this property or method.
When I debug, the line:
Me![RegNum].Enabled = False
is highlighted.
Im lost as to why it's not working.
Thanks!

Thanks for the help everyone.

It's working well, except for one issue. When I got to the next
record, I get an error 13, type mismatch with the line:

Me![Text18].Enabled = (Me![MBE] = True)

highlighted under Private Sub Form_Current()

Any ideas?
 
Your checkbox could be null. Try setting the default of the checkbox to 0.
--
Bob Larson
Access MVP
Access World Forums Administrator
Utter Access VIP

Tutorials at http://www.btabdevelopment.com

__________________________________


radink said:
Oops that should be this:

Me.txtRegNum.Enabled = Me.chkMBE

forgot to name the checkbox chkMBE instead of txtMBE....

Bob L


Make sure that RegNum is actually the name of the text box and not the
field. I usually rename my controls just to make sure that there is no
question as to which is which. I name the controls like txtRegNum so I
know that I am getting the text box. Also, when using the Bang (!)
character, the primary (not exclusive) use is to designate a field and not
the control. I use the dot when referring to a control and a bang when
referring to a field.
So I would rewrite your code like this (after changing the control names)
plus this is easier (one line):
Me.txtRegNum.Enabled = Me.txtMBE
Plus in your original code you were checking the checkbox field as a
string "-1" instead of using True or -1 without the quotes.

Bob Larson
Access MVP
Access World Forums Administrator
Utter Access VIP
Free Access Resources athttp://www.btabdevelopment.com
I have a check box and a text box. I want to disable the text box if
the check box is not checked.
Im using:
If Me![MBE].Value = "-1" Then
Me![RegNum].Enabled = True
Else
Me![RegNum].Enabled = False
I put this in both the code for the form current and the check box.
When i switch back to the standard entry view, I get the error:
Run-Time Error 438
Object doesn't support this property or method.
When I debug, the line:
Me![RegNum].Enabled = False
is highlighted.
Im lost as to why it's not working.

Thanks for the help everyone.

It's working well, except for one issue. When I got to the next
record, I get an error 13, type mismatch with the line:

Me![Text18].Enabled = (Me![MBE] = True)

highlighted under Private Sub Form_Current()

Any ideas?
 
Bob and I seem to be tripping over one another. <g>

If you set a default for the field in the table, be sure to update all the
nulls with a query like this:
UPDATE MyTable
SET MyField = 0
WHERE MyField IS NULL

If you do this with all Yes/No fields, you won't get tripped up on nulls.

--
Bill Mosca, MS Access MVP
http://www.thatlldoit.com
http://mvp.support.microsoft.com/profile/Bill.Mosca
http://tech.groups.yahoo.com/group/MS_Access_Professionals




boblarson said:
Your checkbox could be null. Try setting the default of the checkbox to
0.
--
Bob Larson
Access MVP
Access World Forums Administrator
Utter Access VIP

Tutorials at http://www.btabdevelopment.com

__________________________________


radink said:
Oops that should be this:

Me.txtRegNum.Enabled = Me.chkMBE

forgot to name the checkbox chkMBE instead of txtMBE....

Bob L



Make sure that RegNum is actually the name of the text box and not
the
field. I usually rename my controls just to make sure that there is
no
question as to which is which. I name the controls like txtRegNum so
I
know that I am getting the text box. Also, when using the Bang (!)
character, the primary (not exclusive) use is to designate a field
and not
the control. I use the dot when referring to a control and a bang
when
referring to a field.

So I would rewrite your code like this (after changing the control
names)
plus this is easier (one line):

Me.txtRegNum.Enabled = Me.txtMBE

Plus in your original code you were checking the checkbox field as a
string "-1" instead of using True or -1 without the quotes.

--

Bob Larson
Access MVP
Access World Forums Administrator
Utter Access VIP
Free Access Resources athttp://www.btabdevelopment.com

I have a check box and a text box. I want to disable the text box if
the check box is not checked.

Im using:

If Me![MBE].Value = "-1" Then
Me![RegNum].Enabled = True
Else
Me![RegNum].Enabled = False

End If

I put this in both the code for the form current and the check box.
When i switch back to the standard entry view, I get the error:

Run-Time Error 438

Object doesn't support this property or method.

When I debug, the line:

Me![RegNum].Enabled = False

is highlighted.

Im lost as to why it's not working.

Thanks!

Thanks for the help everyone.

It's working well, except for one issue. When I got to the next
record, I get an error 13, type mismatch with the line:

Me![Text18].Enabled = (Me![MBE] = True)

highlighted under Private Sub Form_Current()

Any ideas?
 

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

Back
Top