Access with VB II

I would like to have a click button to clear this form, how do I add it.


Private Sub Command1_Click()
Dim db As Database
  Dim rstData As Recordset
  Dim strSQL As String
  Set db = OpenDatabase("C:\ps\employees.mdb")
  strSQL = "SELECT * FROM Contacts"
  Set rstData = db.OpenRecordset(strSQL)
  rstData.AddNew
  rstData!firstname = txtFirstName.Text & ""
  rstData!lastname = txtLastName.Text & ""
  rstData!workphone = txtWorkPhone.Text & ""
  rstData!emailaddress = txtEmailAddress.Text & ""
  rstData.Update
  rstData.Close
  db.Close
End Sub
CMILLERAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PaulHewsCommented:
Private Sub cmdClear_Click()
    Dim ctl As Control
    For Each ctl In Me.Controls
        If TypeOf ctl Is TextBox Then
            ctl.Text = ""
        End If
    Next
End Sub

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CMILLERAuthor Commented:
thanks

I did change it to this: Private Sub Command2_Click()

It didnt work with the cmdClear_click(), I am sure it is because I didnt know what else to change
PaulHewsCommented:
>It didnt work with the cmdClear_click(), I am sure it is because I didnt know what else to change

It's generally a good practice to give a descripting name for your controls.  The same way you named your text boxes txtFirstName, txtLastname etc in the property windows, I named my Clear button cmdClear... the event procedure you see there relates to that.

I notice that you've asked a lot of really basic questions in the last few days.  If you need further help with this form, you still have credit left over from the 500 points you put on this question.  I would rather see a complete solution worthy of the points in *this* question, then get 10000 points for answering a series of really easy questions.  It adds more value to the experts exchange database of answers that way.
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

CMILLERAuthor Commented:
Ok, I forgot about needing to change it in the properties window, thanks

Thanks, I understand about the points, I guess most of the time I need a quick response, so I add more points.

Plus, I think the way I was looking at it was, since I am paying the monthly fee to EE it didnt matter how many points I gave a question. I do see and understand your point about the value to the EE.

Yes, I am very new to VB and I hope like everything else the more you do it the better you get. My way of learning is more of looking at something and breaking it down to be able to understand it, I have bought a few books over the last month but they always leave out most of what you need.

I really like this site ( EE ), There are alot of really Sharp people willing to spend there time to answer these questions,
I have a lot of respect for that.

-Chris
PaulHewsCommented:
>Yes, I am very new to VB and I hope like everything else the more you do it the better you get.

That is definitely the case.  :)  

>There are alot of really Sharp people willing to spend there time to answer these questions, I have a lot of respect for that.

Yes, me too.  I can tell you that I've learned an awful lot by participating at this site.  I work in a very small company, and this is pretty much the only exposure I get to other programmers doing the same kinds of things that I'm doing.  It gives me some way to reflect on the different ways of doing things, and seeing what are accepted standards in the field.  :)
sirbountyCommented:
Paul is of course too modest - he's helped me many times as well. :^)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.