How to Correctly Enable/Disable controls with Form_Current

D

David

Hi, I have a form containing a tabb control. On one of the tabs I have some
controls which I want enabled or disabled depending on the value in 2
checkboxes. ONe checkbox refers to a subform which I want to enable/disable
and the other checkbox is for 5 text boxes which I want to enable/disable.

So I have a routine called UpdateControls which is called from the
After_Update events on each of the checkboxes and also from the Form_Current
event so that when the user moves back and forth through the records, the
controls reflect the check box values.

I have 2 problems.

The first is that the underlying recordset seems to go into 'edit mode' when
I set focus to a another control (can't disable a control that has the focus,
so I set the focus to a control on the same tab that is always enabled)
before enabling or disabling the controls. I am just setting teh focus, I'm
not entering any values.

The second is that the controls don't always enable/disable as they should
when the code is called from the Form_Current routine. There seems to be a
delay. They update correctly when I move to the NEXT record again, but then
of course they are displaying as per the values of the previous record!

Here is my code:

Private Sub Form_Current()
'This routine is called when the form is loaded, when the user moves
from one record to another etc.
UpdateControls
End Sub

Private Sub UpdateControls()
'This routine sets controls up the way we want. So controls are
enabled/disabled etc.

'You can't disable a control that has the focus. So have to check for
that first and set the focus to
'something else if this is the case.
'The value property of the tab control stores the active page index.
If TabCtlPersonalDetails = REGULAR_GIVING_PAGE Then
' This is the regular giving tab.
Me.txtSignUpLocation.SetFocus 'If I comment our this line, the
record does not go into edit mode. But I'll get an error if the focus on a
control I'm going to disable.
'Beep 'Used this to be absolutely sure the code was getting called.
End If


'Enable or disable the credit card subform as required.
If chkRegularGiverViaCreditCard.Value = True Then
subFrmCreditCardInfo.Enabled = True
Else
subFrmCreditCardInfo.Enabled = False
End If



'Enable or disable the direct debit controls as required.
If chkRegularGiverViaDirectDebit.Value = True Then
txtAccountNumber.Enabled = True
txtNameOfAccount.Enabled = True
txtBankName.Enabled = True
txtBranch.Enabled = True
txtTownOrCity.Enabled = True
Else
txtAccountNumber.Enabled = False
txtNameOfAccount.Enabled = False
txtBankName.Enabled = False
txtBranch.Enabled = False
txtTownOrCity.Enabled = False
End If


End Sub

My form is a split form. It also contains some other subforms on other
pages of the tab control.

Thanks

David
 
D

David

Hi, I really need som help on this. Have I not posted my question properly?

Cheers

David
 

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

Top