Solved

Clearing information in Access form

Posted on 2014-01-13
4
333 Views
Last Modified: 2014-01-13
I am trying to add a button to my form that will clear the information from the form when clicked.

This is an unbound form with information coming from different tables, so attaching the macro for adding a new record isn't working. It won't clear a list box that I have on the form.

I have a piece of code that I put behind the button, and it works the first time. But when I try to use it again it stops working.

Private Sub cmdClearForm_Click() 
'Create a command button called 'cmdClearForm' on your form and create this event

On Error Resume Next

'Create label on form called 'lblDisplayMessagePleaseWait' and set visible = false
lblDisplayMessagePleaseWait.Visible = True
me.repaint
Application.Echo False
DoCmd.Close acForm, Me.FormName, acSaveNo
DoCmd.OpenForm "frmYour_Form_Name_Here", acNormal

End Sub

Private Sub Form_Load()

On Error Resume Next

DoCmd.Maximize
Application.Echo True

End Sub

Open in new window


I got this code from another website, so I am sure I could be using it wrong.

Thank you!
0
Comment
Question by:Megin
  • 2
  • 2
4 Comments
 
LVL 27

Accepted Solution

by:
MacroShadow earned 500 total points
ID: 39777931
Try this.

Private Sub cmdClearForm_Click()
Dim ctl As Control
For Each ctl In Me.Controls
Select Case ctl.ControlType
Case acTextBox, acComboBox, acListBox, acCheckBox
ctl.Value = Null
Case Else
End Select
Next ctl
End Sub

Open in new window

0
 

Author Comment

by:Megin
ID: 39777946
Do I only list the type of items I have on my form in line 5 (acComboBox, acListBox)?
0
 
LVL 27

Expert Comment

by:MacroShadow
ID: 39777956
yes.
0
 

Author Closing Comment

by:Megin
ID: 39777965
BEAUTIFUL!

Thank you!!!
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

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…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Familiarize people with the process of utilizing SQL Server functions 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 Ac…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

815 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

11 Experts available now in Live!

Get 1:1 Help Now