disabling field under specific conditions

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hello...
i was trying to find a way , some fields in a form get appeard disabled (you
can nt import value) if, for example another column had a specific value .
is that possible? thanks
 
hello Duane thanks for your replay but can u be more specific pls because i
have no
idea about coding ....i have a form(B) with a field "cost" , this form is a
subform in another form (A) with a field "speciality" (for
example)....everytime where "speciality" take a pecific value "AA" the "cost"
field to get disabled...
thanks:)
 
Open the main form in design view and find the On Current event of the form.
Double-click the On Current event to display:
On Current: [Event Procedure]
Then click the [...] to the right of this property to display the module
window for your form.

Your code window should display:

Private Sub Form_Current()

End Sub

Add this line:

Private Sub Form_Current()
DisableSome
End Sub

Then add this code below the End Sub

Sub DisableSome()
'change the control names to match yours
If Me.txtSpecialy = "AA" Then
Me.sfrmName.Form!txtCost.Enabled = False
Else
Me.sfrmName.Form!txtCost.Enabled = True
End If
End Sub

Then add code to the After Update event to the control txtSpecialty

Private Sub txtSpecialty_AfterUpdate()
DisableSome
End Sub

This should disable the txtCost control on your subform when txtSpecialty on
your main form has the value "AA".
 
Thanks!!!

Duane Hookom said:
Open the main form in design view and find the On Current event of the form.
Double-click the On Current event to display:
On Current: [Event Procedure]
Then click the [...] to the right of this property to display the module
window for your form.

Your code window should display:

Private Sub Form_Current()

End Sub

Add this line:

Private Sub Form_Current()
DisableSome
End Sub

Then add this code below the End Sub

Sub DisableSome()
'change the control names to match yours
If Me.txtSpecialy = "AA" Then
Me.sfrmName.Form!txtCost.Enabled = False
Else
Me.sfrmName.Form!txtCost.Enabled = True
End If
End Sub

Then add code to the After Update event to the control txtSpecialty

Private Sub txtSpecialty_AfterUpdate()
DisableSome
End Sub

This should disable the txtCost control on your subform when txtSpecialty on
your main form has the value "AA".
--
Duane Hookom
Microsoft Access MVP


vassilis said:
hello Duane thanks for your replay but can u be more specific pls because i
have no
idea about coding ....i have a form(B) with a field "cost" , this form is a
subform in another form (A) with a field "speciality" (for
example)....everytime where "speciality" take a pecific value "AA" the "cost"
field to get disabled...
thanks:)
 
Hello Duane
the code is working fine, i would like to ask u if its possible to add more
values into the ....If Me.txtSpecialy = "AA" Then...sentence , "AA, BB,CC"
is it valid?
and to be more annoying , what changes can be made for disabling more
txtBoxes?
in the example below we disabled the txtCost ...
if you have time only ...

Duane Hookom said:
Open the main form in design view and find the On Current event of the form.
Double-click the On Current event to display:
On Current: [Event Procedure]
Then click the [...] to the right of this property to display the module
window for your form.

Your code window should display:

Private Sub Form_Current()

End Sub

Add this line:

Private Sub Form_Current()
DisableSome
End Sub

Then add this code below the End Sub

Sub DisableSome()
'change the control names to match yours
If Me.txtSpecialy = "AA" Then
Me.sfrmName.Form!txtCost.Enabled = False
Else
Me.sfrmName.Form!txtCost.Enabled = True
End If
End Sub

Then add code to the After Update event to the control txtSpecialty

Private Sub txtSpecialty_AfterUpdate()
DisableSome
End Sub

This should disable the txtCost control on your subform when txtSpecialty on
your main form has the value "AA".
--
Duane Hookom
Microsoft Access MVP


vassilis said:
hello Duane thanks for your replay but can u be more specific pls because i
have no
idea about coding ....i have a form(B) with a field "cost" , this form is a
subform in another form (A) with a field "speciality" (for
example)....everytime where "speciality" take a pecific value "AA" the "cost"
field to get disabled...
thanks:)
 
It sounds like you are 'growing' new conditions. Is this going to continue or
is there a limited number of conditions and functionality that will be
finite? Once you get beyond a couple instances, you are better off (IMHO)
managing this with data.

AA, BB,CC must have something in common that should be stored in a table and
used from your code. You should be maintaining data records, not code.

Otherwise, you can use
If Me.txtSpecialy = "AA" Or Me.txtSpecialty ="BB" or Me.txtSpecialty = "CC"
Then

or

If Instr("AABBCC", Me.txtSpecialty) > 0 Then

--
Duane Hookom
Microsoft Access MVP


vassilis said:
Hello Duane
the code is working fine, i would like to ask u if its possible to add more
values into the ....If Me.txtSpecialy = "AA" Then...sentence , "AA, BB,CC"
is it valid?
and to be more annoying , what changes can be made for disabling more
txtBoxes?
in the example below we disabled the txtCost ...
if you have time only ...

Duane Hookom said:
Open the main form in design view and find the On Current event of the form.
Double-click the On Current event to display:
On Current: [Event Procedure]
Then click the [...] to the right of this property to display the module
window for your form.

Your code window should display:

Private Sub Form_Current()

End Sub

Add this line:

Private Sub Form_Current()
DisableSome
End Sub

Then add this code below the End Sub

Sub DisableSome()
'change the control names to match yours
If Me.txtSpecialy = "AA" Then
Me.sfrmName.Form!txtCost.Enabled = False
Else
Me.sfrmName.Form!txtCost.Enabled = True
End If
End Sub

Then add code to the After Update event to the control txtSpecialty

Private Sub txtSpecialty_AfterUpdate()
DisableSome
End Sub

This should disable the txtCost control on your subform when txtSpecialty on
your main form has the value "AA".
--
Duane Hookom
Microsoft Access MVP


vassilis said:
hello Duane thanks for your replay but can u be more specific pls because i
have no
idea about coding ....i have a form(B) with a field "cost" , this form is a
subform in another form (A) with a field "speciality" (for
example)....everytime where "speciality" take a pecific value "AA" the "cost"
field to get disabled...
thanks:)


:

You can create a function or sub in your form's module like:

Sub DisableSome()
If Me.chkSomeField = False Then
Me.txtDateField.Enabled = False
Else
Me.txtDateField.Enabled = True
End If
End Sub

You could then call this sub from the On Current event of the form and the
After Update event of chkSomeField.
--
Duane Hookom
Microsoft Access MVP


:

hello...
i was trying to find a way , some fields in a form get appeard disabled (you
can nt import value) if, for example another column had a specific value .
is that possible? thanks
 

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