Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

browsing content in combobox without showing the dropdown

Posted on 2011-09-22
22
Medium Priority
?
312 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
Ever wonder what it's like to get hit by ransomware? "Tom" gives you all the dirty details first-hand – and conveys the hard lessons his company learned in the aftermath.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

715 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