Solved

Clearing information in Access form

Posted on 2014-01-13
4
326 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 26

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 26

Expert Comment

by:MacroShadow
ID: 39777956
yes.
0
 

Author Closing Comment

by:Megin
ID: 39777965
BEAUTIFUL!

Thank you!!!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
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…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

746 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

12 Experts available now in Live!

Get 1:1 Help Now