Results 1 to 5 of 5
  1. #1
    redekopp is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2015
    Location
    Saskatoon
    Posts
    108

    Clearing unbound search fields - code isnt working

    Hi there, my code is giving me a 'You can't assign a value to this object." error when I try to clear the search fields

    Here is my code:
    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
                ctl.Value = Null
            Case acCheckBox
                ctl.Value = 0
            End Select
        
        Next
        
        'Remove the form's filter.
        'DoCmd.RE
        Me.FilterOn = False
    End Sub
    it keeps debugging on the null value .

    Thanks for any help!

  2. #2
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Do you know which control it is failing on? You can use debug.print ctl.name to find out.

    Once you know which control it is, what is the control source setting for that control?

  3. #3
    redekopp is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2015
    Location
    Saskatoon
    Posts
    108
    It turns out to be the export to excel sheet button. how do I avoid buttons that are in my header??

  4. #4
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Your code as written should ignore command buttons (acCommandButton). You could try putting a Case Else (with no actions) in to the Select Case block, but you shouldn't have to.

    A silly question, maybe, but are you sure the "Export to Excel" really is a command button, and not a text box with an On_Click event?

    What you could do is to use debug.print to get the names and control types of all the controls in the header (outside the Select Case block). Comment out the value reset lines so you don't get the error.

  5. #5
    redekopp is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2015
    Location
    Saskatoon
    Posts
    108
    it turned out to be the record count text field. a simple if else statement fixed it.
    Thanks for your replies though John_G!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Unbound Combo box search not working
    By CQCDave in forum Macros
    Replies: 6
    Last Post: 10-19-2015, 02:23 PM
  2. VBA Search code not working
    By rmrha21 in forum Programming
    Replies: 3
    Last Post: 12-02-2014, 10:59 AM
  3. Replies: 10
    Last Post: 11-08-2012, 08:03 PM
  4. Can anyone see why this isnt working please?
    By shabbaranks in forum Programming
    Replies: 3
    Last Post: 12-23-2011, 03:19 AM
  5. Could someone explain why this code isnt working please?
    By shabbaranks in forum Programming
    Replies: 7
    Last Post: 10-29-2011, 09:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums