Solved

browsing content in combobox without showing the dropdown

Posted on 2011-09-22
22
303 Views
Last Modified: 2012-06-21
Hi,
I need to use a keydown (arrow down and arrow up) to browse through the content of a combobox in my form instead of using the mouse click and choose the content from the pop-up combobox .
but very important thing , i don`t need to show the dropdown list that appear when i press keydown and also need to run the beforeupdate event when i choose from combobox content
0
Comment
Question by:drtopserv
  • 9
  • 6
  • 2
  • +2
22 Comments
 
LVL 77

Expert Comment

by:peter57r
Comment Utility
Sounds like you need to use a listbox rather than a combo.
0
 

Author Comment

by:drtopserv
Comment Utility
can`t i use combobox?
0
 
LVL 77

Expert Comment

by:peter57r
Comment Utility
I don't see how you can stop a combo box from dropping down.
0
 

Author Comment

by:drtopserv
Comment Utility
well, if u think so, then how can i change all related code for cbobox to lstbox easily/?
0
 

Author Comment

by:drtopserv
Comment Utility
also can i remove the arrows in that listbox? (hide them?)
0
 
LVL 15

Expert Comment

by:Eyal
Comment Utility
have you considered JQuery as alternative?

i'm sure you will find what you are looking for there

0
 

Author Comment

by:drtopserv
Comment Utility
?
0
 
LVL 15

Expert Comment

by:Eyal
Comment Utility
this can be a direction?
http://harvesthq.github.com/chosen/
0
 
LVL 44

Expert Comment

by:Leigh Purvis
Comment Utility
But, for now, in Access and VBA...
Sounds like you're wanting something like:

Private Sub cboCtl_KeyDown(KeyCode As Integer, Shift As Integer)
    
    Dim intAdd As Integer
    
    intAdd = Switch(KeyCode = 40, 1, KeyCode = 38, -1)

    If (Me.cboCtl.ListIndex > 0 And intAdd = -1) Or (Me.cboCtl.ListIndex < Me.cboCtl.ListCount - 1 And intAdd = 1) Then
        Me.cboCtl.ListIndex = Me.cboCtl.ListIndex + intAdd
        DoCmd.CancelEvent
    End If
    
End Sub

Open in new window

0
 

Author Comment

by:drtopserv
Comment Utility
Wow man!!
works perfectly!!
from where u got this code, do u have samples around that may help me out:}}}
i`ll glad to have ones:}
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 44

Expert Comment

by:Leigh Purvis
Comment Utility
I wrote it.  I've done the like of it before.  (It too was probably for a forum question - I can't recall ever have this as an application's business requirement. ;-)

I have various samples of other stuff in the link in my profile.  I suppose I could amalgamate this into one of them - or make another at some stage.  We'll see.

Cheers.
0
 

Author Comment

by:drtopserv
Comment Utility
WoW man works:}}}}
the small problem is, that when i got into the last record (when i move through the list in combobox by pressing the down arrow and reach the last choise from the list in combobox) and press again down-arrow it jump into the control tabs in subform , i need the way that when i reach the last record to stop in there and then i can press again up-arrow and move up from list in combobox.
is it possible?
0
 
LVL 44

Expert Comment

by:Leigh Purvis
Comment Utility
The behaviour you describe was deliberate. :-)
The simplest way to achieve what you want is to cancel the keypress event regardless.
(i.e. move the DoCmd.CancelEvent line outside of the If statement.)

A more rigorous check would be to simply cancel arrow key presses altogether. (Though you could easily ammend that to be for down arrow only.)
Private Sub cboCtl_KeyDown(KeyCode As Integer, Shift As Integer)
    
    Dim intAdd As Integer
    
    intAdd = Switch(KeyCode = 40, 1, KeyCode = 38, -1)

    If (Me.cboCtl.ListIndex > 0 And intAdd = -1) Or (Me.cboCtl.ListIndex < Me.cboCtl.ListCount - 1 And intAdd = 1) Then
        Me.cboCtl.ListIndex = Me.cboCtl.ListIndex + intAdd
    End If

    If intAdd <> 0 Then
        DoCmd.CancelEvent
    End If
    
End Sub

Open in new window

0
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
I've requested that this question be closed as follows:

Accepted answer: 500 points for LPurvis's comment http:/Q_27321757.html#36984865

for the following reason:

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0
 

Author Comment

by:drtopserv
Comment Utility
It works, but i have seems small problem, instead of using arrow to go up/down i was able to write the start letter of a name from list and it autocomplete and jump to the word from the list, now and i start typing the initial letter it gives me error in the line :
 intAdd = Switch(KeyCode = 40, 1, KeyCode = 38, -1)

with run-time error 94:
invalid use of null
?
0
 
LVL 44

Accepted Solution

by:
Leigh Purvis earned 500 total points
Comment Utility
No problem, though you could mention that at any stage, no need to wait for the cleanup volunteers to have done their (valuable, time consuming) rounds and then object.
Just bring it up.
Allowing for characters...

intAdd = Switch(KeyCode = 40, 1, KeyCode = 38, -1, 1, 0)
0
 

Author Comment

by:drtopserv
Comment Utility
First of all i apologize for the delay. sorry!
I`m struggling trying to understand what that line of code means:

intAdd = Switch(KeyCode = 40, 1, KeyCode = 38, -1, 1, 0)
it will be kindly from u if u explain me this line..
thanks in regard.
0
 
LVL 44

Expert Comment

by:Leigh Purvis
Comment Utility
It just adds to new parameters to the Switch function. (Which can be seen documented in Online help by hitting F1 while you have the cursor on the Switch keyword in your VBA code.)

The new parameters are such that if the KeyCode passed to the procedure is neither 40 nor 38, then it returns a numeric value to the intAdd variable - rather than attempting (and failing) to return Null.

The new parameters are:
1, 0
The 1 is just a literal value, a condition which is always True (any always-True value or expression could have been used, for example 1=1), the zero is the value which the function then returns.
The result is just that any value which isn't 40 or 38 returns zero.
0
 

Author Comment

by:drtopserv
Comment Utility
perfect bro, thnx alot..
btw Lpurvis, may u plz guide to web/ebook around any around heavy stuff related to access,i`d like to read:}
thxn alot anyway..u got ur 500 point:}
0
 
LVL 44

Expert Comment

by:Leigh Purvis
Comment Utility
lol The 500pts I can live without.  Glad you're sorted though.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now