Solved

Clearning a text box

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

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…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

832 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