Disable text box on form

reidhaus

Registered User.
Local time
Today, 14:34
Joined
Dec 18, 2007
Messages
23
I would like for a field to become disabled and left blank based on a combo box selection. I wrote in a code that I thought would work - but it doesn't. Any ideas where I went wrong?

Private Sub Company_BeforeUpdate(Cancel As Integer)
If Category = "MG" Then
Company.Enabled = True
Else
Company.Enabled = False
End If

End Sub

The "Company.Enabled = False" line is where I'm getting the error message.
confused.gif
 
What is the error message you get?
 
I've been tinkering with it ever since and can't get the same error message as when I first posted this thread. That code never did "disable" the field (actually, it is a combo box, not text box). The message I had received, though, to answer your question, was something about not being able to do it when the field has focus. I was under the assumption that code would not have allowed the focus in the first place. Silly me.

Am I looking at this correctly? Should the field already be disabled upon opening the form and only enabled when the criteria is correct for the first field? If so, then I can see how my code would not work but am unsure how to proceed.:(
 
Your code is in the wrong control/wrong event, and also needs to be in the Form_Current event to persist as you move from record to record.
Code:
Private Sub Category_AfterUpdate()
 If Me.Category = "MG" Then
  Company.Enabled = True
 Else
  Me.Company = Null
  Company.Enabled = False
 End If
End Sub
Code:
Private Sub Form_Current()
 If Me.Category = "MG" Then
  Company.Enabled = True
 Else
  Company.Enabled = False
 End If
End Sub

Linq ;0)>
 
Not sure if it matters but I already have a code on Form_Current:

Private Sub Form_Current()
InventoryItem.Requery
End Sub

I did copy your code but now get two new error messages. The first says: The expression you entered on current as the event property setting produced the following error: Ambiguous name detected: Form_current.

Then I get: "Enter paramater value" pop-up message:
Forms!frm_Shipping!Category
 
Not sure if it matters but I already have a code on Form_Current...
...now get two new error messages. The first says: The expression you entered on current as the event property setting produced the following error: Ambiguous name detected: Form_current.
The first error message means that there are more than one Form_Current Subs and you can't do this! You simply have to combine the code in a single Form_Current event:
Code:
Private Sub Form_Current()

 InventoryItem.Requery

 If Me.Category = "MG" Then
  Company.Enabled = True
 Else
  Company.Enabled = False
 End If

End Sub
Don't forget to delete the other Form_Current sub you're not using.

Take care of this and then we'll address your other problem. A parameter box popping up generally means a field used in a Query or the Form based on a Query cannot be found by Access.

Linq ;0)>
 
Ahhhhh....now I'm getting somewhere! Okay, so I redid the code and sure enough, the field is disabled on each new record. AND I'm not getting a single error message. THANKS!!! :)
But....the field does not enable until I tab out of the record then click back in despite having the category chosen correctly. A puzzler.:eek:
 
For it to happen as soon as you make a selection from Category you have to have the code I gave you for the Category_AfterUpdate event, as well as the code in the Form_Current event. It sounds as if you haven't done that.

Linq ;0)>
 

Users who are viewing this thread

Back
Top Bottom