473,385 Members | 1,925 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,385 software developers and data experts.

Use VBA to set or select a specific row in a bound combo box

Hi,
I'm using MS Access 2002. I have a form with a combo box built from a
query that returns one column, and that one column is the bound column.

How do you use VBA to programmatically change which row in the combo
box is selected??
I looked at the forum and the answers aren't very clear. Of course the
MS Access help file is worthless.

Thanks!!
Vmusic

Jul 23 '06 #1
9 32580
me.cboPickSomething = "SomeValue From the List"

Jul 23 '06 #2
No... that's not it.

My question was:
How do you use VBA to programmatically change which row in the combo
box is selected??

I don't want to set the value to some arbitrary string - I want to use
VBA code to select one of the valid rows or items in a bound combo box

Please.......
Thanks
Vmusic
pi********@hotmail.com wrote:
me.cboPickSomething = "SomeValue From the List"
Jul 23 '06 #3
"Vmusic" <ak*****@irisicom.netwrote in
news:11*********************@s13g2000cwa.googlegro ups.com:
No... that's not it.

My question was:
How do you use VBA to programmatically change which row in the
combo box is selected??

I don't want to set the value to some arbitrary string - I
want to use VBA code to select one of the valid rows or items
in a bound combo box

Please.......
Thanks
Vmusic
pi********@hotmail.com wrote:
>me.cboPickSomething = "SomeValue From the List"
Yes that is it. it's the only way that works. You as a
programmer simply need to examine the list, extract the string
you want from the list, and then do as you were told

--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Jul 23 '06 #4
No, No, No..... what kind of .... is this programming language

Look I have a combo box. It is populated from data that runs from a
query- and it is bound to a column in a table.

When the user changes or selects a different value than what is
initially displayed - the BeforeUpdate or AfterUpdate method fires.

I want to prompt the user to confirm they REALLY want to change their
value - If they don't confirm - or say no, then I want to change the
value back to what it originally was. In order to change the value back
- I have to programattically change the ListIndex or some stupid
property in the combo box.

How do you use VBA to programmatically change which row in the combo
box is selected??

I do not want to set it to some arbitrary string value. I want the
actual row selected to be programmatically changed... because it's
bound to a value in a table - which itself is a lookup.

There HAS TO be a way to programmatically change the selected row in a
combo box?

Sorry - it seems like a simple question/ task.. but I have yet see a
clear answer, maybe even with a VBA code example

PLEASE don't tell me that if I write the code in the BeforeUpdate
method, and Exit Sub if they say no, that the change won't take place.
It does....

Thanks!!!!!
Vmusic
Bob Quintal wrote:
"Vmusic" <ak*****@irisicom.netwrote in
news:11*********************@s13g2000cwa.googlegro ups.com:
No... that's not it.

My question was:
How do you use VBA to programmatically change which row in the
combo box is selected??

I don't want to set the value to some arbitrary string - I
want to use VBA code to select one of the valid rows or items
in a bound combo box

Please.......
Thanks
Vmusic
pi********@hotmail.com wrote:
me.cboPickSomething = "SomeValue From the List"
Yes that is it. it's the only way that works. You as a
programmer simply need to examine the list, extract the string
you want from the list, and then do as you were told

--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com
Jul 23 '06 #5
Sorry, first prerequisite to a helpful answer is a proper definition of
the problem.

Jul 24 '06 #6
"Vmusic" <ak*****@irisicom.netwrote in
news:11*********************@75g2000cwc.googlegrou ps.com:
When the user changes or selects a different value than what is
initially displayed - the BeforeUpdate or AfterUpdate method
fires.

I want to prompt the user to confirm they REALLY want to change
their value - If they don't confirm - or say no, then I want to
change the value back to what it originally was. In order to
change the value back - I have to programattically change the
ListIndex or some stupid property in the combo box.

How do you use VBA to programmatically change which row in the
combo box is selected??
As long as the focus remains on the control, and the combo box is
bound to a field, you have access to the OldValue property.

Otherwise (unbound combo boxes are not uncommon, though there'd be
no reason to confirm a change, seems to me), you could cache the
original value in a variable in the OnEnter event of the combo box,
and use that to change it back.

But to select a row, you have two choices:

1. set the value (the sensible way), OR

2. set it by listindex (this is convenient when you want to
automatically select, say, the first entry in the dropdown).

To do it the second way, you'd have to know which row in the list
had the value you wanted. Obviously, it makes much more sense to
just store the value and restore to that.

Which is basically what you were told, even if you didn't like the
answer.

BTW, I was tempted not to bother to answer because you were so
damned rude in your responses to the help you were given. Had you
simply described your task in full, you could have had a good answer
a long time ago.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Jul 24 '06 #7
Well, I suppose I should know how to do this. But I don't. Why not? I
guess because if a user Clicks on A, and doesn't like that, he/she can
then Click on B. So I've never had any cause to want to say, "Did you
really mean A?" and if not, return the box to its pre-A state.

ListIndex can be very gnarly, or at least it has been in my experience.
In a listox, one can set ListIndex if the control has the focus, and if
it hasn't, one can call its SetFocus method and then set the ListIndex
value. But on a sleepy Sunday night, this does not seem to work for a
combo box. Maybe in the bright clear light of morning ....

Well, I suppose we could figure out some way ... but in the meantime
probably someone will contribute something simple that I (and you too,
maybe) have completely overlooked.

As time goes by and I get less and less enthralled by the Access UI, I
generally use little forms which I size and place as required in place
of combo and list boxes. In a few ways they are more responsive than
combo and list boxes, but not in all ... but that's another story.

Jul 24 '06 #8
"Vmusic" <ak*****@irisicom.netwrote in
news:11*********************@75g2000cwc.googlegrou ps.com:
No, No, No..... what kind of .... is this programming
language

Look I have a combo box. It is populated from data that runs
from a query- and it is bound to a column in a table.

When the user changes or selects a different value than what
is initially displayed - the BeforeUpdate or AfterUpdate
method fires.

I want to prompt the user to confirm they REALLY want to
change their value - If they don't confirm - or say no, then I
want to change the value back to what it originally was. In
order to change the value back - I have to programattically
change the ListIndex or some stupid property in the combo box.
The advice given is still valid.

When the user enters the combobox, the OnEnter event fires. You
store the existing value of the combobox to a variable. When the
user has finished changing the data, the before update event
fires. Then you decide the user is a bigger fool than you, When
he answers in the affirmative, you change it back, using the
statement given in previous messages.

However, because you explained your problem a little better, you
can actually use the cancel feature of the combobox (also of
text and list boxes) before update event.
If the user answers "No I wass being stupid, and I don't want to
chage the data," in your messagebox, you put the statement
cancel = true ' stops the event
me.combobox.undo ' reverse all changes since the box received
focus.
How do you use VBA to programmatically change which row in the
combo box is selected??

I do not want to set it to some arbitrary string value. I want
the actual row selected to be programmatically changed...
because it's bound to a value in a table - which itself is a
lookup.

There HAS TO be a way to programmatically change the selected
row in a combo box?

Sorry - it seems like a simple question/ task.. but I have yet
see a clear answer, maybe even with a VBA code example

PLEASE don't tell me that if I write the code in the
BeforeUpdate method, and Exit Sub if they say no, that the
change won't take place. It does....

Thanks!!!!!
Vmusic
--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Jul 24 '06 #9
Bob Quintal <rq******@sPAmpatico.cawrote in
news:Xn**********************@66.150.105.47:
However, because you explained your problem a little better, you
can actually use the cancel feature of the combobox (also of
text and list boxes) before update event.
If the user answers "No I wass being stupid, and I don't want to
chage the data," in your messagebox, you put the statement
cancel = true ' stops the event
me.combobox.undo ' reverse all changes since the box received
focus.
That's the only real solution. I suggested using the BeforeUpdate
event and OldValue to revert, but you can't change the value in the
BeforeUpdate event, you can only accept it or cancel the edit, as
you describe above.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Jul 24 '06 #10

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

Similar topics

14
by: Jos? | last post by:
This one droves me completely mad. I did not succeed to exploit the track given to me by Bob. I have : three tables : Clubs, Persons and ClubsPersons that join the two first in a many to many...
1
by: Ryann | last post by:
Hello. I have a form with a series 5 combo-boxes. All 4 contain the same query which lists Parts based on a productID from a previous form. i.e. cboPart1 = Part ID, Part, ProductID Where...
3
by: yb | last post by:
I have a unbound mult-select listbox field named "Locations".Multi-select option is set to "Extended". I'm having problem saving the values from this field into table. I have text column...
4
by: LD | last post by:
Is there a way in Access to store more than one value in a field that has been selected from a combo box? For example, if a combo box had three values that you can select, "One", "Two", and...
3
by: Stig | last post by:
Hi, Any help on this one will be greatly appreciated as I have spent too long banging my head against the screen trying to get it sorted. Basically I would like to have a select all records...
5
by: njb35 | last post by:
Hi all I'm beginning my foray from VBA into VB 2005 Express, and enjoying some of the efficiencies it provides! I'm stuck with some dataset handling however that I _think_ can be automated but...
2
by: csolomon | last post by:
Hello: I am creating a form that will calculate a value based on the value selected from a case statement in a function. The function I created is called GetYield and accepts 3 arguments. I...
10
by: BeaBea | last post by:
Hi All, I have been reading some of the threads in your forum and decided to join and post my question. Hopefully it won't be too lengthy. I have created an Unbound Form called paramform2. ...
40
by: chhines | last post by:
I have a very long IIf statement. I think maybe I've reached the limit of how many choices you can have in the control source "Build" statement of a text box on a form. Really, the IIF statement is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.