Results 1 to 4 of 4
  1. #1
    justinwright is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jul 2010
    Posts
    104

    Clearing certain boxes on form for next record using VB

    I have the following code:



    Code:
    Private Sub Command26_Click()
        DoCmd.GoToRecord , , acNewRec
        Dim c As Control
            ' Enumerate Controls collection.
            For Each c In Me.Controls
            If c.ControlType = acTextBox Then
            c.Value = Null
            End If
            Next c
        Me.txtCheckNumber.Visible = False
        Me.txtDateItem.Visible = False
        Me.Deduct_Add.Value = Null
    End Sub
    This code clears all of the fields, but I wanted to clear everything EXCEPT two fields: ACHGROUP and PDATE. The fields that I DO want cleared are: SITE, PAMOUNT, Deduct/Add, DESC, DESC1, DESC1, Initial.

    Anyone have any ideas? Any help is appreciated!
    Last edited by justinwright; 07-21-2010 at 10:39 AM. Reason: Bolded relevant parts of code

  2. #2
    justinwright is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jul 2010
    Posts
    104
    Pardon the double post, but I figured it out. After "Next c" I just redefined the default values that I wanted for the boxes, so that it cleared everything still, but readded the ones I wanted readded as default.

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    One common solution to this type of problem is using the Tag property of the controls. You might put "Clear" in the Tag property of the controls you want to clear, then your test would be:

    If c.Tag = "Clear" Then
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    justinwright is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jul 2010
    Posts
    104
    Ah okay, thanks

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

Similar Threads

  1. Error when clearing form
    By turbo910 in forum Forms
    Replies: 11
    Last Post: 11-26-2009, 11:03 AM
  2. Replies: 3
    Last Post: 06-27-2009, 03:53 PM
  3. Replies: 7
    Last Post: 05-16-2009, 08:08 AM
  4. clearing a form
    By macsterling in forum Forms
    Replies: 0
    Last Post: 07-31-2008, 10:38 AM
  5. Clearing the clipboard with VBA?
    By Simon Sweet in forum Programming
    Replies: 1
    Last Post: 04-17-2008, 03: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