Enable field

pm4698

Registered User.
Local time
Today, 18:46
Joined
Jan 23, 2010
Messages
72
Hello there!
I am new in access.

I have created a table. My problem is about 3 fields.
I have a field that is a drop-down menu.
All i want is when i choose a specific option from the drop-down menu to enable the other two fields.
Otherwise, the two other fields are disabled.
How can i do that?

Thank you in advance!
 
something like this perhaps

Code:
Private Sub Combo1_Change()
    If Combo1.ListIndex > -1 Then
        Command1.enabled = True
    Else
        Command1.enabled = False
    End If
End Sub
 
Thank you.
So, the value '-1' at your code, is for the first value of the combo-box field?If i want the second value should i put '0' for example?

I have microsoft access 2007. Where should i insert this type of code and how can i use it at my table?

thanks in advance
 
A Table is where you store your data
A form is where you make the user interface and enable, disable etc
 
Ok. I created a form and i dragged the 3 fields from the table. I clicked on the combo - box field and i selected the after-update option and insert code and i wrote this:

Private Sub Field_Name_AfterUpdate()
If Combo1.ListIndex > -1 Then
command1.Enabled = True
Else
command1.Enabled = False
End If
End Sub

the "-1" value is for the first option of the combo box?If yes, the second value is "0" and the second is "1" etc?

How can i configure which field will be enabled?If for example the field's name is taxes, should i write:

taxes.enabled = True?

Thanx in advance
 
I dont know what the rowsource is on your combo

If Me.Field_Name.column(0) = "Taxes" Then
Me.Taxes.enabled = true
Me.SomeOtherField.enabled = false
End If
 
Ok. I created a form and i dragged the 3 fields from the table. I clicked on the combo - box field and i selected the after-update option and insert code and i wrote this:

Private Sub Field_Name_AfterUpdate()
If Combo1.ListIndex > -1 Then
command1.Enabled = True
Else
command1.Enabled = False
End If
End Sub

the "-1" value is for the first option of the combo box?If yes, the second value is "0" and the second is "1" etc?

How can i configure which field will be enabled?If for example the field's name is taxes, should i write:

taxes.enabled = True?

Thanx in advance


Copy the rowsource and paste here. The "-1" value refers to non-selection. Any value above -1 (i.e. from 0 up) means that a selection is made. However, if you have Column Heads property set to yes, then your first selection is 1 and not 0.
 
OK.
I have 3 fields of the same table. The names of the 3 fields are "Price" "Tax" and "Date". The Price - field is a combo-box with these values:
<100
<200
<300

I want when i select the 3rd option of the field "Price", to enable the other two fields, so the user can fill in. Otherwise, if another value of this field is selected, the two other fields will be disactivated.
So, i drag the 3 fields at my form.
I chose the combo - box field and i choose the after-update option and then the code and i write this:

Option Compare Database

Private Sub Price_AfterUpdate()
If Price.ListIndex > -1 Then
Tax.Enabled = True
Date.Enabled = True
Else
Tax.Enabled = False
Date.Enabled = False
End If
End Sub

Should this work?If not and also if i am mistaken at the way of thinking, please let me know.

Thank you in advance
 
I tend not to use the AfterUpdate event. I prefer to use the Change event. With this event, this is what I would do:

Code:
If Price.ListIndex > -1 And Price.Text = "<300" Then
Tax.Enabled = True
Date.Enabled = True
Else
Tax.Enabled = False
Date.Enabled = False
End If
I would also advise you change the name of your Date control to something else.
 
Last edited:
i wrote over "Price" field this

Private Sub Price_Change()
If Price.ListIndex > -1 And Price.Text = "<300" Then
Tax.Enabled = True
priceless.Enabled = True
Else
Tax.Enabled = False
priceless.Enabled = False
End If
End Sub


When i try to test the form, the Tax and Priceless fields are enabled and function indepedently from the piece of code i wrote.

Any ideas?
 
what piece of code are you referring to? paste it here. and what do you mean by "function independently"? in what context
 
I use microsoft access 2007. I have created a table and i want to fill it through a form. So, i went to new form tab. I drag 3 fields of the table in the form. The names of the fields are "Price", "Tax" and "Priceless".

I have defined from the table that the field "Price" will be a combo box and i have entered 3 options:
<100
<200
<300

At the form, all i want is that only when i choose the option <300, only then i can fill in the other two fields. Otherwise i cannot fiil in these fields because they will be disabled.

So, while i am in the form, i choose the combo box field, right click, properties and a right menu appears. At the right menu, i choose the 3rd option and at the tab, "at change", i push a button with 3 dots. A window appear and i choose the 3rd option, that says something about adding code. I think that opens the visual basic platform and i get this:

Private Sub Transfer_Change()

End Sub

At this point, i write between the first and the last line this:

If Price.ListIndex > -1 And Price.Text = "<300" Then
Tax.Enabled = True
Priceless.Enabled = True
Else
Tax.Enabled = False
Priceless.Enabled = False
End If

But when i open the form, i can fill in the "Tax" and "Priceless" fields at all occasions, whether the option of "Price" field is <100 or <200 or <300.
 
Depending on what you want, change the Enabled property of Priceless and Tax to No. For me to understand what's going on with your combo box, add this line of code to the On Click event: Msgbox "The value is: " & Price.Value

Save, and compile. Then open your form and click on a value on the combo box and tell me what value you selected, and what message you see.
 
I get an error:

run_time error "424":
object required

when i choose an option at combo box Price and the two other fields are enabled
 
Here is the sample of my database.
If you change it let me know what you did.

Thanks in advance
 

Attachments

Interestingly I can't seem to edit your controls, forms or code. Comes up with these characters in (I presume) a foreign language? I'm getting #Name? errors in the bottom two fields which could mean you are referencing the data incorrectly with the wrong names.
 
Here it is.
I work this database at Greek language.
I think i changed it to english
 

Attachments

Still the same. What you've done is change the names but the language of the database is still greek. Do a quick search for how to change the language.
 
Here it is.
I work this database at Greek language.
I think i changed it to english


Don't worry about that. I've just imported your table and created a new form. Just like I thought you were using the wrong names for the control. What you may have done was change the "Caption" of the control's label and not the name. The name of a control can be found under the "Other" tab. For now don't change the names, just put this amended code in there:

Code:
Private Sub Price_AfterUpdate()
    If Price.ListIndex > -1 And Price.Value = "<300" Then
        Date1.Enabled = True
        Date2.Enabled = True
    Else
        Date1.Enabled = False
        Date2.Enabled = False
    End If
End Sub
 

Users who are viewing this thread

Back
Top Bottom