Solved

Clearning a text box

Posted on 2014-04-23
4
253 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 27

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 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
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…
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…
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…

910 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