Results 1 to 5 of 5
  1. #1
    dccjr's Avatar
    dccjr is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2012
    Location
    Colorado Springs, CO
    Posts
    138

    Error When Clearing Controls on a Form

    Hello all,

    I am using the following code to clear all of the textboxes and comboboxes on a form.

    Code:
    Private Sub Form_Load()
    Dim oneControl As Object
    intStartNo = 1
    For Each oneControl In Me.Controls
    Select Case oneControl.ControlType
    Case acTextBox
    oneControl.Value = ""
    Debug.Print oneControl.Name
    Case acComboBox
    oneControl.Value = ""
    Debug.Print oneControl.Name
    End Select
    Next oneControl
    Me.tbxMatSetID = intStartNo
    Me.tabSpotData.Visible = False
    Me.tabStudData.Visible = False
    Me.tabGTAWData.Visible = False
    Me.tbxMatSetID = intStartNo
    Me.tbxTackSetID = intStartNo
    Me.tbxTechSetID = intStartNo
    End Sub
    I initally got a "Run Time Error 2448 - You cannot assign a value to this object" on one of the textboxes. It happened about 3/4 of the way through all of the controls. After searching all of the properties for what might be causing this, I deleted the textbox and recreated it. When I ran it again, I got the same error, but this time on the control before the replaced one. (I have a breakpoint at the beginning of the Select Case and am stepping through while watching the list appear in the Immediate Window.) I replaced that one, and the problem moved up to the one before it. I have done this for all 7 controls on the tab. Now, It has jumped back to the last control on the previous tab.

    This seems very peculiar, and other than working backwards through the controls, has no obvious cause. Does anyone have any suggestions?

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    Did not look at the whole thing but considering only the error the following line and similar stand out.

    Me.tbxMatSetID = intStartNo

  3. #3
    dccjr's Avatar
    dccjr is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2012
    Location
    Colorado Springs, CO
    Posts
    138
    Why? I'm assigning the value to the variable after clearing the fields. I don't think the code is making that far. However, I will check it once get to work.

    Any other ideas?

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    The error you get is the control is busy so you can not change its properties.
    Insert the following before you change your Tabs' visible properties

    Me.tbxMatSetID.SetFocus

  5. #5
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Everything else aside, if you're looping through the Controls Collection

    Dim oneControl As Object

    needs to be

    Dim oneControl As Control

    What, exactly, are you trying to accomplish, here? If the Controls have data, when the Form is first opened, one has to assume that the Form is Bound, and deleting data from a Record immediately on opening the Form is unusual, to say the least. Are any of the Controls populated through expressions/formulas in their Control Sources? Are any of the Bound Controls tied to an Autonumber Field?

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

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

Similar Threads

  1. Clearing a search box on a form
    By pbouk in forum Forms
    Replies: 13
    Last Post: 02-06-2013, 04:54 PM
  2. Clearing a Form
    By dabatman in forum Forms
    Replies: 4
    Last Post: 01-20-2012, 11:51 AM
  3. Clearing a form - having real issues
    By mike_980 in forum Forms
    Replies: 9
    Last Post: 01-11-2012, 06:15 AM
  4. Error when clearing form
    By turbo910 in forum Forms
    Replies: 11
    Last Post: 11-26-2009, 11:03 AM
  5. clearing a form
    By macsterling in forum Forms
    Replies: 0
    Last Post: 07-31-2008, 10:38 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