Solved

Acces 2007 - code syntax

Posted on 2014-12-27
5
146 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 119

Assisted Solution

by:Rey Obrero
Rey Obrero 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 34

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now