Enabling form fields

Del_Piero_3

Registered User.
Local time
Today, 20:57
Joined
Jul 20, 2004
Messages
33
I have a subform which disables certain fields based on the value entered. The problem I am having is that when I click on add new record, the form stays in the last state with disabled fields. Basically I want all the field to be enabled when add new record button is clicked. I hope it makes sense.

Kind Regards
 
you can use the controlname.enabled = true on the add button
 
maxmangion said:
you can use the controlname.enabled = true on the add button

Thanks for the reply. I forgot to say, the add new record button is on the main form and the fields that I want to be enabled are in the subform. I am newbie so am sorry for asking a such stupid question, what dou you mean by the controlname - am I suppose to put the name of the button there?

Kind Regards
 
by controlname i meant the name of the field which is disabled at the moment.
 
Code:
Me.YourSubForm.SetFocus
Me.YourControl.Enabled = True
 
maxmangion said:
by controlname i meant the name of the field which is disabled at the moment.

The disabled fields vary, each record has different fields which are disabled so whatever the state of the last record I viewed, it will have those disabled fields when clicked add new record.
 
Post the code behind your "Add New" control and the names of all controls that could be disabled.
 
i.e. on click of your add button you should have:

me.field1.enabled = true
me.field2.enabled = true
etc! note that you need to replace field1, field2, etc with the names of your controls.
 
maxmangion said:
i.e. on click of your add button you should have:

me.field1.enabled = true
me.field2.enabled = true
etc! note that you need to replace field1, field2, etc with the names of your controls.
That won't work because you'll have to set the focus on the subform first to enable the controls on it.
 
___ said:
Post the code behind your "Add New" control and the names of all controls that could be disabled.

Heres is the code, I get the following compile error: Method or data member not found. I think it is not recognising my fields. This code is in the main form (frm_allSlideDetails) and the fields are in the subform (subfrm_slideDetails)

Code:
Private Sub addRecord_Click()
On Error GoTo Err_addRecord_Click

 DoCmd.GoToRecord , , acNewRec
    
 Me.suitableReview = True
 Me.reason.Enabled = False
 Me.slideInadequate.Enabled = True
 Me.slideNegative.Enabled = True
 Me.moderate.Enabled = True
 Me.severe.Enabled = True
 Me.invasive.Enabled = True
 Me.glandular.Enabled = True
 Me.borderline.Enabled = True
 Me.mild.Enabled = True
 Me.abNormalCells.Enabled = True
 Me.difficultIdentify.Enabled = True
 Me.reason2.Enabled = True   
      
Exit_addRecord_Click:
    Exit Sub

Err_addRecord_Click:
    MsgBox Err.Description
    Resume Exit_addRecord_Click
    
End Sub
 
yes of course but i just gave him the example how to carry on with the other controls, because you had already informed him to set the focus in your previous post.

alternatively he can do it as follows:

Me.SubformName.Form!ControlName.Enabled = True
 
you are getting the error because you either have to setfocus on the subform as ____ suggested or else using the following:

Me.SubformName.Form!ControlName.Enabled = True
 
Try this
Code:
Private Sub addRecord_Click()
On Error GoTo Err_addRecord_Click  

Dim ctrl As Control

  DoCmd.GoToRecord , , acNewRec
  Me.subfrm_slideDetails.SetFocus

    For Each ctrl In Me.Controls
        If ctrl.ControlType = acTextBox Then
            ctrl.Enabled = True
        End If
    Next

Exit_addRecord_Click:
    Exit Sub

Err_addRecord_Click:
    MsgBox Err.Description
    Resume Exit_addRecord_Click
    
End Sub
 
Last edited:
____ example is neater since you have several controls on the form.
 

Users who are viewing this thread

Back
Top Bottom