?
Solved

combobox

Posted on 1998-10-15
6
Medium Priority
?
143 Views
Last Modified: 2010-04-30
I want to have a dbcombo box in a form with some data from one of my tables.
How can I do this wihout a datacontrol (unbound).

Give a example please.
Thanks
0
Comment
Question by:asimoes
[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
  • 4
  • 2
6 Comments
 
LVL 5

Accepted Solution

by:
chewhoung earned 100 total points
ID: 1440222
Use this function:

gsdatabase is a global variable
it is storing the path and the name of the database.
Put the function in a module, and call from a form load event like this:

Call PopCombo("ProductType", Me.cboProductType)



Sub PopCombo(TableName As String, MyCombo As Control)

Dim MyDB As Database, MyRS As Recordset
Dim MyIndex As Integer, MyColumn As Integer, TempCount As Integer

Set MyDB = OpenDatabase(gsDatabase)
Set MyRS = MyDB.OpenRecordset(TableName, dbOpenDynaset)

MyColumn = MyCombo.ColumnCount - 1
MyIndex = 0
TempCount = 0

With MyRS
Do While Not MyRS.EOF
    MyCombo.AddItem , MyIndex
    For TempCount = 0 To MyColumn
        MyCombo.Column(TempCount, MyIndex) = MyRS.Fields(TempCount)
        MyCombo.Column(TempCount, MyIndex) = MyRS.Fields(TempCount)
    Next TempCount
   
    MyIndex = MyIndex + 1
    MyRS.MoveNext
Loop
End With

MyRS.Close
MyDB.Close

End Sub
0
 

Author Comment

by:asimoes
ID: 1440223
I've made a button in the form calling the module where I did put the Sub PopCombo code.
I've also have a DBcombo box object that have the "MyCombo" name, right?
1º It gives an error with the  word -->   cboProductType what is this?
2º Must it be a DBCombo box or a combo box will do it?
Thanks
0
 
LVL 5

Expert Comment

by:chewhoung
ID: 1440224
You for got to change the calling part:

Call PopCombo("ProductType", Me.cboProductType)

To

Call PopCombo("YourTable", Me.MyCombo)

I've been using DBCombo. I'm not sure whether Combo box can run but you can try.
0
Independent Software Vendors: 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!

 
LVL 5

Expert Comment

by:chewhoung
ID: 1440225
Remember to set the global variable to
gsDatabase = "C:\YOURDATABASE.MDB"

I set it in the Sub Main where it will be called when my program starts.
0
 

Author Comment

by:asimoes
ID: 1440226

For the words ColumnCount and AddItem it gives the error
"Object does not suport this property or method"
I'm using VB 4.0.
0
 
LVL 5

Expert Comment

by:chewhoung
ID: 1440227
I'm using VB5. VB4 DBCombo does not support columncount and additem property. For the ColumnCount part, you can remove it. But for the adding item part, I'm not sure what property it use for adding item. Can you check the help?

MyRS.Fields(0) indicate that add the first field in the table to combo box. To add 2nd field to combo box use MyRS.Fields(1).


Sub PopCombo(TableName As String, MyCombo As Control)

Dim MyDB As Database, MyRS As Recordset
Dim MyIndex As Integer

Set MyDB = OpenDatabase(gsDatabase)
Set MyRS = MyDB.OpenRecordset(TableName, dbOpenDynaset)

MyIndex = 0

With MyRS
Do While Not MyRS.EOF
    MyCombo.AddItem MyRS.Fields(0)

    MyRS.MoveNext
Loop
End With

MyRS.Close
MyDB.Close

End Sub

0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month10 days, 1 hour left to enroll

762 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