Solved

Acces 2007 - code syntax

Posted on 2014-12-27
5
155 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 37

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 50

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 50

Expert Comment

by:Gustav Brock
ID: 40520397
You are welcome!

/gustav
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

710 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