how to attach macro to combo button

G

Guest

Hi Pam,

What exactly is a combo button? Did you mean combo box?

Tom
____________________________

does anyone know.
 
F

fredg

does anyone know

Are you keeping score, or somewhere here do you have a serious
question about Access?
If you do have a serious question, perhaps you might re-phrase it so
that a potential responder will know what it is you wish to do.

There is nothing that I know of in Access that is called a Combo
Button. Perhaps you meant a Combo Box or perhaps a Command Button, but
but until the question is clear, and you give some indication of what
you need done, don't expect too much help.
 
P

pam

I am very sorry for not being clear. I have a combo box that allows the user
to pick an area from 5 choices. I need to add to this combo box a macro or a
way for a form to open with only the data from the area the user selected in
the combo box.
 
T

Tom Wickerath

Or put it behind a command button. Did you see my response
to your post with the subject "comand button" (8/17/2004,
12:59 PM)? I outlined a method for you in that reply.

Tom
_________________________________
 
F

fredg

I am very sorry for not being clear. I have a combo box that allows the user
to pick an area from 5 choices. I need to add to this combo box a macro or a
way for a form to open with only the data from the area the user selected in
the combo box.

Now you're cookin'!
Let's not use a macro, but do it using code.

You want to open the form with records from a particular area.
I first need to ask, what is the datatype of the bound column of the
combo box? Is there only one column in the combo box with data, such
as "West Coast", which is Text? or is the bound column a number, such
as 5, which signifies an area?

OK. Let's assume it is text, and that there is a field in your table
that is named [Area].

You have a combo box on your form. You wish to select an area from
that combo box and have a different form open showing just records
from that area.

Display the Combo Box's Property sheet.
Click on the Data tab.
On the AfterUpdate event line, write:
[Event Procedure]
Then click on the button with the 3 dots that appears on that line.
When the code window opens, the cursor will be flashing between 2
already existing line of code.

Between those 2 lines write:

DoCmd.OpenForm "NameOfForm", , ,"[Area] = '" & Me![ComboName] & "'"

Exit the code window.

When you open this form and select an area from the combo box, the
other form will open with just the records from that area.

If, however, the bound column of the combo box is a number datatype,
then code the AfterUpdate event like this:

DoCmd.OpenForm "NameOfForm", , ,"[Area] = " & Me![ComboName]

Change "NameOfForm" to the actual name of the form you wish to open,
and change [Area] and [ComboName] to the actual name of the field and
the actual name of your combo box.

For more information on using the OpenForm method, look in VBA help
files.

If you would like to close the original form, or hide it, when the
second form opens, add another line of code under the line above.
To simply hide the first form:
Me.Visible = false

To actualy close the first form:
DoCmd.close acForm, Me.Name

In this case you can write it exactly as I have. Do not change Name.

Hope this helps.
 
F

fredg

Would I be able to do the same with a report? I mean create a combo box where
user selects area, and then report for that area opens

fredg said:
I am very sorry for not being clear. I have a combo box that allows the user
to pick an area from 5 choices. I need to add to this combo box a macro or a
way for a form to open with only the data from the area the user selected in
the combo box.

:

On Tue, 17 Aug 2004 12:37:02 -0700, pam wrote:

does anyone know

Are you keeping score, or somewhere here do you have a serious
question about Access?
If you do have a serious question, perhaps you might re-phrase it so
that a potential responder will know what it is you wish to do.

There is nothing that I know of in Access that is called a Combo
Button. Perhaps you meant a Combo Box or perhaps a Command Button, but
but until the question is clear, and you give some indication of what
you need done, don't expect too much help.

Now you're cookin'!
Let's not use a macro, but do it using code.

You want to open the form with records from a particular area.
I first need to ask, what is the datatype of the bound column of the
combo box? Is there only one column in the combo box with data, such
as "West Coast", which is Text? or is the bound column a number, such
as 5, which signifies an area?

OK. Let's assume it is text, and that there is a field in your table
that is named [Area].

You have a combo box on your form. You wish to select an area from
that combo box and have a different form open showing just records
from that area.

Display the Combo Box's Property sheet.
Click on the Data tab.
On the AfterUpdate event line, write:
[Event Procedure]
Then click on the button with the 3 dots that appears on that line.
When the code window opens, the cursor will be flashing between 2
already existing line of code.

Between those 2 lines write:

DoCmd.OpenForm "NameOfForm", , ,"[Area] = '" & Me![ComboName] & "'"

Exit the code window.

When you open this form and select an area from the combo box, the
other form will open with just the records from that area.

If, however, the bound column of the combo box is a number datatype,
then code the AfterUpdate event like this:

DoCmd.OpenForm "NameOfForm", , ,"[Area] = " & Me![ComboName]

Change "NameOfForm" to the actual name of the form you wish to open,
and change [Area] and [ComboName] to the actual name of the field and
the actual name of your combo box.

For more information on using the OpenForm method, look in VBA help
files.

If you would like to close the original form, or hide it, when the
second form opens, add another line of code under the line above.
To simply hide the first form:
Me.Visible = false

To actualy close the first form:
DoCmd.close acForm, Me.Name

In this case you can write it exactly as I have. Do not change Name.

Hope this helps.

Sure.
In the combo's AfterUpdate event:

DoCmd.OpenReport "ReportName",acViewPreview, ,"[Area] = '" &
Me![ComboName] & "'"
 
Top