Solved

Clearing information in Access form

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Familiarize people with the process of utilizing SQL Server views 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 Access…
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…

688 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