Solved

browsing content in combobox without showing the dropdown

Posted on 2011-09-22
22
306 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
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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

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 100

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 500 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

This article will show you how to use shortcut menus in the Access run-time environment.
Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

856 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