Solved

Acces 2007 - code syntax

Posted on 2014-12-27
5
153 Views
Last Modified: 2014-12-28
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
Comment
Question by:jegajothy
5 Comments
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 100 total points
ID: 40520098
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
 
LVL 36

Assisted Solution

by:PatHartman
PatHartman earned 100 total points
ID: 40520141
"" 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
 
LVL 49

Accepted Solution

by:
Gustav Brock earned 300 total points
ID: 40520318
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
 

Author Closing Comment

by:jegajothy
ID: 40520380
Thank u to everyone for their solutions.  Gustav's solution was what I was looking for, thank u and well done.
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 40520397
You are welcome!

/gustav
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question