Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

browsing content in combobox without showing the dropdown

Posted on 2011-09-22
22
Medium Priority
?
314 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
20 Comments
 
LVL 77

Expert Comment

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

Author Comment

by:drtopserv
ID: 36579496
can`t i use combobox?
0
 
LVL 77

Expert Comment

by:peter57r
ID: 36579558
I don't see how you can stop a combo box from dropping down.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

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

Author Comment

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

Expert Comment

by:Eyal
ID: 36579706
have you considered JQuery as alternative?

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

0
 

Author Comment

by:drtopserv
ID: 36579712
?
0
 
LVL 15

Expert Comment

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

Expert Comment

by:Leigh Purvis
ID: 36579834
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
ID: 36594347
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
 
LVL 44

Expert Comment

by:Leigh Purvis
ID: 36594876
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
ID: 36984520
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
ID: 36984865
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 101

Expert Comment

by:mlmcc
ID: 37143547
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
ID: 37130395
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 2000 total points
ID: 37130626
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
ID: 37130705
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
ID: 37130723
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
ID: 37143614
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
ID: 37146564
lol The 500pts I can live without.  Glad you're sorted though.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Cancel future meetings from user mailboxes in Office 365 using Remove-CalendarEvents
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

824 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