Making fields inactive

  • Thread starter Thread starter mon
  • Start date Start date
M

mon

I have a form which has a drop combo list where an
appropriate number needs to be added to another field. ie
travelling time needs hours, kilometres needs kms and
allowance needs $. Which is the best: seperate fields
for for each different type? If that is so how can I make
the two inappropriate text boxes inactive? There are about
15 items in the combo box, one only for $ and one only for
Km's. The others entries are all hours or just comments
with no other numbers required to be entered. (Actually,
on thinking about it I probably need seperate fields
because that would be tidier for linking or joining later,
Eh?? what do youall think? Thanks Monika
 
I don't fully follow what you're up to, but if the data is different, you should probably
have different fields.

To disable a control you would manipulate the Enabled and/or Locked properties of the
control. Another option is the controls Visible property, which would make it disappear.
To control these from code is easy:

Me.txtMyTextbox.Enabled = True

You would use True or False as appropriate replacing Enabled with either Locked or Visible
to manipulate the other two.

Enabled and Locked work in conjunction with each other.

Enabled = True, Locked = False
Normal Control

Enabled = False, Locked = False
Grayed Out, you can't click into it or change it manually.

Enabled = True, Locked = True
Normal Looking control, but you can't change it manually. You can click into it and drag
the mouse over its contents to highlight it in order to copy its contents for pasting
elsewhere.

Enabled = False, Locked = True
Normal Looking control, but you can't click into it or do anything else to it manually.

When I say you can't change it manually, it can be changed through code.
 
Thanks Wayne. Just a bit further, please. I have a combo
box based on a table. When for example the kilometres
record is selected I would like the hour and $ box to be
inactive so that they can't enter kilometres into those
fields.
Thanks Monika
-----Original Message-----
I don't fully follow what you're up to, but if the data
is different, you should probably
have different fields.

To disable a control you would manipulate the Enabled
and/or Locked properties of the
control. Another option is the controls Visible property, which would make it disappear.
To control these from code is easy:

Me.txtMyTextbox.Enabled = True

You would use True or False as appropriate replacing
Enabled with either Locked or Visible
 
I still don't fully follow what you are trying to do. If, what they are entering is just a
number, then it sounds as if the data is the same and you are qualifying it with the combo
box. If that is the case, then you could probably get by with one field. You would want to
pop-up a warning if they then change the combo box and ask them if they really want to
change $2.57 to 2.57 Km.

To disable a textbox when changing the combo box you would use the AfterUpdate event of
the combo box to run the code mentioned in the previous message. You would take the
current value of the combo box and disable the desired controls.

Example:

Select Case Me.cboMyCombo
Case "Km"
Me.txtMoneyTextbox.Enabled = False
Case "$"
Me.txtKilometerTextbox.Enabled = False
Case Else
Msgbox "Somehow we got a bad value.", vbOkOnly
End Select
 
thanks for your patience Wayne.
I'll try to explain: I have a combo box based on a table.
the table has about 13 records, (two fields) eg
INA13 Investigation Time
INA14 Travelling Time
INA14 Kilometres
INA16 Reimbursements Claimed
etc
Only one record for Kilometres and only one record for
Money.
I have three text boxes on the form: Hours, KM's and Cost
When the user chooses eg INA13 or INA 14 I would like the
Km's and cost fields (text boxes to be inactive. When the
user chooses KM's I would like the Hours and cost boxes to
be inactive.
Thanks Mon
-----Original Message-----
I still don't fully follow what you are trying to do. If,
what they are entering is just a
number, then it sounds as if the data is the same and you
are qualifying it with the combo
box. If that is the case, then you could probably get by
with one field. You would want to
pop-up a warning if they then change the combo box and
ask them if they really want to
change $2.57 to 2.57 Km.

To disable a textbox when changing the combo box you
would use the AfterUpdate event of
 
Ok, to enable/disable the textboxes, see the example in the previous message. However,
since it seems that you are simply entering one and only one number for each record (time
(1 of 2), distance, or cost) you could keep the number value in a single field and use the
selection in the combo box to determine what that field stands for. Dealing with them as
separate fields, as you currently have it, is also easy. Also, should you decide to use 2
at a time later, if they are separate now it will be much easier to make the change.

Something you may want to consider is placing the textboxes on top of each other and using
the Visible property of the textboxes to only make the appropriate one visible instead of
enabling/disabling them. This would tidy up your form a little by only needing space for
one textbox. You would use the same code as in the previous message, only set the Visible
property instead of the Enabled property.

The code in the previous message was to be placed in the AfterUpdate event of the combo
box, but you would also need it in the Form's OnCurrent event to make it work as you went
through records that already exist.
 
Thanks Wayne, working nicely with "visible"
I want to make a selection of Case, can you use "OR".
What is the correct code for
eg Case "KK" or Case "mm"
or do they have to be all seperate
Thanks again Monika
-----Original Message-----
Ok, to enable/disable the textboxes, see the example in the previous message. However,
since it seems that you are simply entering one and only
one number for each record (time
(1 of 2), distance, or cost) you could keep the number
value in a single field and use the
selection in the combo box to determine what that field
stands for. Dealing with them as
separate fields, as you currently have it, is also easy.
Also, should you decide to use 2
at a time later, if they are separate now it will be much easier to make the change.

Something you may want to consider is placing the
textboxes on top of each other and using
the Visible property of the textboxes to only make the
appropriate one visible instead of
enabling/disabling them. This would tidy up your form a
little by only needing space for
one textbox. You would use the same code as in the
previous message, only set the Visible
property instead of the Enabled property.

The code in the previous message was to be placed in the AfterUpdate event of the combo
box, but you would also need it in the Form's OnCurrent
event to make it work as you went
 
The correct code for

Case "KK" or Case "mm" is

Case "KK", "mm"

I'm not sure it is case sensitive, you'll just have to try it, but it may take "kk" and
"KK" as the same thing.
 
Back
Top