Solved

combobox

Posted on 1998-10-15
6
139 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

809 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