473,394 Members | 1,781 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Using a Macro to Set the Value of a Combo Box

Hi Everyone-

I am trying to use a simple macro to set the value of a combo box on a
form, and I can't get it to work.

I have a macro with 2 actions: OpenForm and SetValue. I can open my
form, but I can't get the macro to set the value of a combo box on the
form that opens. I don't need the macro to look up any values, I just
want it to set the value of a combo box.

I have a very simple table called tblDivision. It has 2 fields:

DivisionID (Primark Key, text)
DivisionDescription (text)

DivisionID DivisionDescription
NFC National Football League
AFC American Football League

My form that opens has information about the teams that fall into one
of these 2 leagues, i.e. team city, team name, etc...

At the top of my form, is a combo box. In this combo box, you can
select "NFC" or "AFC" to describe which league the team is in. But I'm
trying to use a command button (on another form) that runs a macro that
will automatically set the value of the combo box on the form to "NFC"
or "AFC." I have one command button that says "Create NFC Team" and
another command button that says "Create AFC Team." Both command
buttons run a macro that opens the same form. Based on which command
button I hit, I want the value of the combo box set to that value. For
instance if I hit the "Create NFC Team" command button, I want my macro
to set the value of my combo box on my team form set to "NFC." And if I
hit the "Create AFC Team" command button, I want the value of the combo
box on my team form set to "AFC."

Basically, I just want the macro to set the value of my combo box to
either "NFC" or "AFC."

In the "Item" dialog box of the "Set Value" action, I have the name of
my control, a combo box named cboDivision.

I'm having problems with the "Expression" part of my "Set Value"
action. I'm not sure what to enter here. I just want to set the value
of the combo box to "NFC" or "AFC" depending on which command button I
hit. I've tried a few things but my macro always halts. I would just
set the "Expression" = "NFC" or = "AFC" but it says that you shouldn't
use the equals sign. Is there any way to do this? I thought it would be
easy, but it has been a pain in my butt!

Thanks!

Megan

Nov 13 '05 #1
1 11780
Yeah, macros basically suck. Once you learn to code a little, you'll
rarely use them again. But, that said, here's what you do...

create a new macro (or modify yours)
steps...
OpenForm: frmTeam
DataMode: Add
WindowMode: Normal
SetValue:
Item: [Forms]![frmTeam]![Division]
Expression: "NFC"

You could convert all this to code and it would look like this:

Option Compare Database

'------------------------------------------------------------
' mcrAddAFC
'
'------------------------------------------------------------
Function mcrAddAFC()
On Error GoTo mcrAddAFC_Err

DoCmd.OpenForm "frmTeam", acNormal, "", "", acAdd, acNormal
Forms!frmTeam!Division = "AFC"
mcrAddAFC_Exit:
Exit Function

mcrAddAFC_Err:
MsgBox Error$
Resume mcrAddAFC_Exit

End Function

Nov 13 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: anita | last post by:
Hi All Can anybody pls help me out with this problem. I have a combo box control which has about 10,000 values in it. These values in the combo box are called from a different table. When i use...
1
by: Patrick_Montana | last post by:
I am having a problem auto-activating a macro when I change data in a field on a form that is a combo box. I have a fair understanding of Microsoft Access but am not a programmer so I am trying to...
1
by: Jo K. | last post by:
I have the following fields in a table. -JobNo (primary key) -Assessor (combo box containing only two names to choose from ie. John, Bill) I have created two seperate reports which have exactly...
10
by: Mindy | last post by:
I am supposed to build a database, and till now, finally I think I get the GUI part of Access. But not sure if it is enough to build a database. For example, if I build two forms, the first form...
0
by: Mindy | last post by:
I am trying to build relationship between my two items on a form. The first one is PickUp By Name, second one is pickup by memberID. These two are all created as combo and saved as "find a record...
7
by: Harris | last post by:
Dear all, I have the following codes: ====== public enum Enum_Value { Value0 = 0, Value1 = 10,
6
by: pedroalves | last post by:
Hi all, This is not a question about how to #define COMMA , Please keep reading. Recently in binutils, we introduced a macro like this: #define STRING_COMMA_LEN(STR) \ (STR), ((STR) ?...
4
by: copewithit | last post by:
Hi all, I'm trying to modify a record (in this case the name associated with the record) to a new name selected by the user in a combo box. Right now I have Single Form with a subform in datasheet...
9
imrosie
by: imrosie | last post by:
Hello, I have a form(PrintPreviewInvoices) that displays past invoices (in a listbox). I added a combo box control in order to filter timeframes;(today, this week, last week, this month, last...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.