Solved

Clearning a text box

Posted on 2014-04-23
4
250 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
  • 2
4 Comments
 
LVL 26

Accepted Solution

by:
MacroShadow earned 500 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 26

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

757 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

25 Experts available now in Live!

Get 1:1 Help Now