Solved

combobox

Posted on 1998-10-15
6
141 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 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

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…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…

738 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