Solved

Clearing information in Access form

Posted on 2014-01-13
4
337 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

734 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