Solved

combobox

Posted on 1998-10-15
6
136 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
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…

744 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

11 Experts available now in Live!

Get 1:1 Help Now