Can't reset my form (1 Viewer)

Status
Not open for further replies.

Angel69

Registered User.
Local time
Today, 08:06
Joined
Jun 11, 2013
Messages
86
I have the below code to reset my subform after I have filtered it using some combo boxes. One of my fields in the underlying table had a calculated field so I'd get an error when clicking the reset button. I edited the query to update the 'type' field and deleted the calculated field in the table but now get another error. The exact error is 'Run-Time error '3327' Field 'Type' is based on an expression and cannot be edited.' It appears it will not reset my form and show all records as long as this field is based on an expression. Any ideas how to get around this?

Code:
Private Sub cmdReset_Click()
      'Purpose:   Clear all the search boxes in the Form Header, and show all records again.
    Dim ctl As Control
 
    'Clear all the controls in the Form Header section.
    For Each ctl In Me.Section(acHeader).Controls
        Select Case ctl.ControlType
        Case acTextBox, acComboBox
        Debug.Print ctl.Name
            ctl.Value = Null
        Case acCheckBox
            ctl.Value = False
        End Select
    Next
 
    'Remove the form's filter.
    Me.frmPacsVerificationSubForm.Form.FilterOn = False
End Sub
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 05:06
Joined
Aug 30, 2003
Messages
36,125
Wrap the line setting to null in an If/Then

If ctl.Name <> "TheCalculatedTextbox" Then
 

Angel69

Registered User.
Local time
Today, 08:06
Joined
Jun 11, 2013
Messages
86
Hi pbaldy, I don't refer to a specific field in the form to clear them but instead I refer to the Text Box and Combo Box control types which are in the header. Somehow it is seeing a control named 'type' in my header but I can't find it. I deleted all controls in my header and ran the code. Instead of my immediate window showing the cboLOB, cboSample and Type fields in the immediate window it showed just 'Type'. I'm not sure how to find this 'hidden' control in my header. Hope this makes sense.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 05:06
Joined
Aug 30, 2003
Messages
36,125
Can you post the db here?
 

Angel69

Registered User.
Local time
Today, 08:06
Joined
Jun 11, 2013
Messages
86
Yes, it's the first form listed under Forms. So when you select yes from the combo box to sample then click 'reset' you see the error. Thanks!
 

Attachments

  • Sample.accdb
    1,008 KB · Views: 25

pbaldy

Wino Moderator
Staff member
Local time
Today, 05:06
Joined
Aug 30, 2003
Messages
36,125
The control named type is hidden behind the subform. It's bound to a field that doesn't exist, hence the error.
 
Status
Not open for further replies.

Users who are viewing this thread

Top Bottom