Writing a macro for a button on a form

S

Sara

I apologize in advance for asking such a simple question. I am
creating a form for work (which I have never done before) and I have
never programmed in VB before (all I have is an extremely bad
beginners book). The form has two combo boxes (that work thanks to
help from others here:) THANKS!!) that pull a value from a chart.
What I would like to do is create a reset button that will default the
combo boxes back to blank. I have tried to do this the easy way by
recording the macro but I must be doing something wrong because it
isn't doing a thing. Does anyone mind helping?

Sara
 
N

Niklas Östergren

Hi Sara!

Try this in your combobox after update event:
===================================
' Set nullstring in control
Me.YourComboBoxName= vbNullString

' Set focus on some control on your form
Me.ControlInYourForm.SetFocus
====================================

This code will erase any string on your combobox and also set focus to any
control you like on your form. If you dont want to set focus anyware els
just delete the last two rows of code!

// Niklas
 
S

Steve Schapel

Sara,

What is meant by "recording the macro"? I am familiar with the concept
in Excel (where the word 'macro' means something completely different
than it does in Access), but there is no facility in Access to "record"
a macro. In this case, if you want to use a macro, just select the
Macros tab in the database window, and click New. In the macro design
window, enter SetValue in the Action column, and then in the Item
argument, put [NameOfYourCombobox] and in the Expression argument, put
Null. Repeat in the second row for the other combobox. Name and save
this macro, and then assign it on the On Click event property of your
command button.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top