[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Clearing information in Access form

Posted on 2014-01-13
4
Medium Priority
?
340 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 2000 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

650 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