• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 175
  • Last Modified:

Acces 2007 - code syntax

My OS is win 7 prof 64 bit, and I use Access 2007.  I have a form, on which there are fields, and I want to clear the contents in them, by clicking on a command button.  This is restart due to a false start. Thus, if I have fields like on the Form's code like :
  Me.1.txt
 me.2.txt
etc
What is the syntax to clear the contents of all the fields with nothing.
Thank u for your response.
0
jegajothy
Asked:
jegajothy
3 Solutions
 
Rey Obrero (Capricorn1)Commented:
to clear textboxes

me.text1=""
me.text2=""

or if your form is bound you can try using

me.undo

to clear everything in the form
0
 
PatHartmanCommented:
"" isn't nothing, it is a zero length string.  A better choice would be null.  "" is only valid for text fields.  It is invalid for numeric fields including dates.

Me.txtFld1 = Null
Me.txtFld2 = Null
0
 
Gustav BrockCIOCommented:
Run this code:

Dim ctl As Control

For Each ctl In Me.Controls
    If ctl.ControlType = acTextbox Then
        Select Case ctl.Name
            Case "txtSomething", "txtSomethingElse"
                ' Preserve the content. Do Nothing.
            Case Else
                ' Clear content.
                ctl.Value = Null
        End Select
    End If
Next

Set ctl = Nothing

/gustav
0
 
jegajothyretiredAuthor Commented:
Thank u to everyone for their solutions.  Gustav's solution was what I was looking for, thank u and well done.
0
 
Gustav BrockCIOCommented:
You are welcome!

/gustav
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now