Solved

How can I bring up dropdown list of DBCombo using code?

Posted on 1998-08-23
18
351 Views
Last Modified: 2008-03-10
As title.
I am looking for something like the CB_SHOWDROPDOWN message of a regular combobox.
0
Comment
Question by:leeal
  • 8
  • 6
  • 2
  • +2
18 Comments
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1430534
I haven't tried, but I'm almost positive it CB_SHOWDROPDOWN will work, since dbcombo is a subclass of regular combo box
0
 
LVL 1

Author Comment

by:leeal
ID: 1430535
It doesn't work. Here's the code I used, it works on Combo but not DBCombo:
-----
Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const CB_SHOWDROPDOWN = &H14F

Public Sub Combo_ShowDropDown(cboControl As Object)
    Dim r As Long
    r = SendMessageLong(cboControl.hWnd, CB_SHOWDROPDOWN, True, 0)
End Sub

Public Sub Command1_Click()
    Combo_ShowDropDown DBCombo1
End Sub

0
 
LVL 10

Expert Comment

by:viktornet
ID: 1430536
Here is the right way =)

r = SendMessageLong(cboControl.hWnd, CB_SHOWDROPDOWN, 1, 0)

Hope this helps =)

Regards,
Viktor Ivanov
0
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1430537
I hope you tested it before posting it as an answer, cause i did, and it didn't work
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1430538
Opps....something else....don't use SendMessageLong....Instead use SendMessage That's a lot better...

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"
          (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long,
          lParam As Any) As Long

Hey I'm not a VB programmer, but I think it will work...try it with SendMessage
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1430539
Did anyone test this example??? . o O

Regards,
Viktor Ivanov
0
 
LVL 1

Author Comment

by:leeal
ID: 1430540
Doesn't work...
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1430541
How about without using

r = SendMessage()

instead use

 SendMessage()

Does this work?

Regards,
Viktor Ivanov
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1430542
Try this......

Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long

Private Sub Combo1_GotFocus ()
      Const CB_SHOWDROPDOWN = &H14F
      Dim Tmp
      Tmp = SendMessage(Combo1.hWnd, CB_SHOWDROPDOWN, 1, ByVal 0&)
End Sub

Hope this works! =)

Regards,
Viktor Ivanov
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:leeal
ID: 1430543
No. It doesn't work.
btw, I don't think it's a syntax problem because it works on the regular combobox.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1430544
Did you try the second example I gave you?

//Vik
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1430545
Let me see the code you are trying to pass..Don't write it again, just copy it from your code

//Vik
0
 
LVL 1

Author Comment

by:leeal
ID: 1430546
It's here already. (the 2nd comment)
The only difference is that I call Combo_ShowDropDown from DBGrid1_ButtonClick event instead of Command1_Click event.
0
 
LVL 4

Expert Comment

by:mcix
ID: 1430547
leeal,

Are you running VB 5 with SP3?
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1430548
In that case I think that something is wrong with the DB control not with code

Regards,
Viktor Ivanov
0
 
LVL 1

Author Comment

by:leeal
ID: 1430549
Yes, I am using SP3.
0
 
LVL 1

Accepted Solution

by:
jsuper earned 100 total points
ID: 1430550
Instead of worrying about all of the Send message API stuff, why don't you just use the sethocus and sendkey commands?  I've tried it out, and it works like a charm.  Just insert the following two lines when you want to force the DBCombo to drop down.

    DBCombo1.SetFocus
    SendKeys ("%{DOWN}"), True

Good Luck.
0
 
LVL 1

Author Comment

by:leeal
ID: 1430551
Thanks, jsuper.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

861 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

20 Experts available now in Live!

Get 1:1 Help Now