Solved

browsing content in combobox without showing the dropdown

Posted on 2011-09-22
22
304 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
 

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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
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 …

867 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

23 Experts available now in Live!

Get 1:1 Help Now