Solved

combobox

Posted on 1998-10-15
6
140 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
  • 4
  • 2
6 Comments
 
LVL 5

Accepted Solution

by:
chewhoung earned 50 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

Technology Partners: 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!

Question has a verified solution.

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

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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 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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

685 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