Combo box text clearance problem

N

naveen prasad

Hi all

I have a form with 6 combo boxes..
c1,c2,c3,c4,c5,c6. each consists of 10 items.

a sub form is added to display all the required records..

now when a item is selected from combo box, the corresponding query will get
the values on the below subform... every thing is going fine....


problem: when c2 is selected, the text in c1 should be cleared.
i mean to say, when any combo box is selected, the previous
selected combo box text should be cleared...

for this i have written a code in each combo box lost focus
private sub c1_lostfocus()
comboc1.text=""

end sub

like corresponding code in all other comboboxes.

now i have selected a item in c1, the result displayed down in subform, to
view all records i tried to move the scroll bars of subform, that time system
is considereing as lost focus action of c1 and the result is dissapearing...


need help here....
 
V

vanderghast

Keeping the LostFocus event, for each control, make a call to
OneChoiceOnly, ie, for combo c1:

--------------
Private Sub c1_LostFocus()
OneChoiceOnly
End Sub
--------------


where OneChoiceOnly can be:

-----------------------------------
Private Sub OneChoiceOnly()
Dim s As String

' DEBUG NOTE: avoid stopping before next line
s = Screen.ActiveControl.Name

NullIfNotMe s, "c1"
NullIfNotMe s, "c2"
NullIfNotMe s, "c3"
NullIfNotMe s, "c4"
NullIfNotMe s, "c5"
NullIfNotMe s, "c6"
End Sub

Private Sub NullIfNotMe(s As String, controlName As String)
If (s <> controlName) Then Me.Controls(controlName).Value = vbNullString
End Sub
--------------------------------




Vanderghast, Access MVP
 
N

naveen prasad

dear sorry to say,, i have a very small problem here...
i have written all according to your advice...

combos c1,c2,c3,c4,c5,c6

example sequence..

1. c1 clicked
2.c2 clicked but c1 not cleared.

3. c3 clicked, c1 cleared but not c2.

4. c4 clicked, c2 cleared but not c3... so on...

each time we can text on 2 combos...

can it be done better with some more code....

pls help
 
V

vanderghast

Indeed, you can click on a second combo box, only when you leave it (we used
the LostFocus event) would it be the only one left with a value.

You can get a more 'natural' behavior using the Change event rather than the
LostFocus event.


Vanderghast, Access MVP
 
N

naveen prasad

I changed all the code from lost focus to change event..

its completly successfull..... thanks a million....

thanks
 
N

naveen prasad

Dear sorry to bother again

I need some information... I want to put a refresh button on the form , when
clicked

all combo boxes should be cleared including the subform values....

I tried to put like

c1.text=""
c2.text=""
so on... but iam getting error as unless control has focus cant be made
null...


pls help me in this.....
 
J

John Spencer

DON'T use the text property, use the value property. Or since the value
property is the default, you don't even need to do that. My preference is to
set things to NULL instead of to a zero-length string ("").

C1=Null

or

C1.Value = NULL


John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County
 
N

naveen prasad

its done... thank you very much dear

John Spencer said:
DON'T use the text property, use the value property. Or since the value
property is the default, you don't even need to do that. My preference is to
set things to NULL instead of to a zero-length string ("").

C1=Null

or

C1.Value = NULL


John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County


.
 

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