Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Clearning a text box

Posted on 2014-04-23
4
Medium Priority
?
277 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 28

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 28

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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Suggested Courses

916 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