Solved

Acces 2007 - code syntax

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

947 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

20 Experts available now in Live!

Get 1:1 Help Now