PDA

View Full Version : Excel VBA



kbp
07-09-2011, 01:56 PM
Hi ya
I am not so good at VBA with excel, so can someone help me please. I have two fields a) Customer number (named as txtCust) and b) Account number (named as txtAccount). I want to write code, if anything entered in customer number field, account number should be disabled and vice versa. So only one field to be allowed to enter at one time.

Bob Phillips
11-09-2011, 01:54 AM
Before I answer your question, a question from me. Will clearing the textbox re-enable the other textbox?

Bob Phillips
11-09-2011, 02:13 AM
I'll take a punt that the answer to my question is yes, so here you go



Private Sub txtCustomer_AfterUpdate()
With Me

If .txtCustomer.Text = "" Then

.txtAccount.Enabled = True
.txtAccount.BackColor = &H80000005
Else

.txtAccount.Enabled = False
.txtAccount.BackColor = &H8000000B
End If
End With
End Sub

Private Sub txtAccount_AfterUpdate()
With Me

If .txtAccount.Text = "" Then

.txtCustomer.Enabled = False
.txtCustomer.BackColor = &H80000005
Else


.txtCustomer.Enabled = True
.txtCustomer.BackColor = &H8000000B
End If
End With
End Sub