Results 1 to 2 of 2
  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

    Clearing Fields for on User Form for New Record

    I am giving the user the option of entering a new record. If they select yes, I am trying to clear the fieldand reset the combo boxes to Null. Here is the code that I was using:

    [code]
    If MsgBox("Would you like to enter another record?", vbYesNo) = vbYes Then
    For Each oneControl In frmDataForm.Controls
    Select Case TypeName(oneControl)
    Case "TextBox"
    oneControl.Text = vbNullString
    Case "ComboBox"
    oneControl.Index = Null
    End Select
    Next oneControl


    Else
    DoCmd.Close acForm, Me.Name
    DoCmd.OpenForm "frmHome", acNormal, "", "", , acNormal
    End If
    [code/]

    When I select Yes, I get the following error on the "You can't reference a property or method for a control or unless the contro has the focus."

    Do I need to set the focus on each object before clearing it? If so, any recommendation on how to do it in the loop?

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Don't use the .Text property, which requires focus. Use the default .Value.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Clearing Combo Box when adding a new record
    By Purdue_Engineer in forum Forms
    Replies: 3
    Last Post: 09-25-2012, 12:57 PM
  2. Clearing Checkbox on New Record
    By rossi45 in forum Programming
    Replies: 5
    Last Post: 04-16-2012, 05:30 PM
  3. Clearing a Form
    By dabatman in forum Forms
    Replies: 4
    Last Post: 01-20-2012, 11:51 AM
  4. issues with Enter/Tab/arrow keys clearing fields
    By Kimberly42506 in forum Access
    Replies: 10
    Last Post: 12-16-2011, 03:32 PM
  5. Clearing certain boxes on form for next record using VB
    By justinwright in forum Programming
    Replies: 3
    Last Post: 07-21-2010, 12:16 PM

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