?
Solved

Clearning a text box

Posted on 2014-04-23
4
Medium Priority
?
273 Views
Last Modified: 2014-04-23
Hi, all!

I have some code that makes a lot of updates to my tables, but I also need it to clear a particular text box after it is done.

The textbox is txtactdesc.

Here is the code:

Private Sub btnTest_Click()

    Dim db      As DAO.Database
    Dim rst     As DAO.Recordset
    Dim strSql  As String
    Dim varDesc As Variant
    Dim lngID   As Long

    varDesc = Me.txtactdesc.Value
    
    strSql = "Select * From Activities Where ActDesc = '" & varDesc & "'"
    
    Set db = CurrentDb
    Set rst = db.OpenRecordset(strSql)
    
    If rst.RecordCount = 0 Then
        rst.AddNew
            rst!ActDesc.Value = varDesc
            rst!ActTypeID.Value = Me!lsttype
            rst!STOID.Value = Me!cmbSTO.Value
            rst!TOID.Value = Me!cmbTO.Value
        rst.Update
        rst.Bookmark = rst.LastModified
    End If
    lngID = rst!ActID.Value

    strSql = "Select Top 1 * From StaffActivities"
    Set rst = db.OpenRecordset(strSql)
    
    rst.AddNew
        rst!ActDate.Value = Nz(Me!ActDate.Value, Date)
        rst!ActID.Value = lngID
        rst!STOID.Value = Me!cmbSTO.Value
        rst!TOID.Value = Me!cmbTO.Value
        
    rst.Update
    
    
    Refresh
    
    rst.Close
    
    Set rst = Nothing
    Set db = Nothing

    
                
End Sub

Open in new window


I have tried the Undo method, setting the text to "", and just telling the text box to refresh or clear. None of it seems to be working.
I might just be putting the command in the wrong place.

Thank you, in advance, for your help!
0
Comment
Question by:Megin
[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
  • 2
4 Comments
 
LVL 27

Accepted Solution

by:
MacroShadow earned 2000 total points
ID: 40018337
Nothing to do with your question, but you should remove all occurrences of ".Value".

As far as your question is concernrd adding the following line at the end of your code will clear the textbox:
txtactdesc = ""

Open in new window

0
 

Author Closing Comment

by:Megin
ID: 40018344
Yep, that worked!

I should have known that. It was so simple!

Thank you!!!
0
 
LVL 27

Expert Comment

by:MacroShadow
ID: 40018369
No prob.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 40018661
Just a note on the Value property....

The default property of many types of controls is the Value property.

so the following:
   Me.myTextbox = 123

is exactly the same time as

  Me.myTextbox.Value = 123

So there is nothing really bad about having the Value property in your code.

It is a little longer, but many use it to explicitly show which property is being referred to.

(it is really a matter of personal preference)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

719 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