?
Solved

Simple question - DataGrid and Combo

Posted on 2003-03-10
9
Medium Priority
?
166 Views
Last Modified: 2010-05-01
Hi everyone!
I have one ComboBox and one Datagrid and i want to show information from an Access database. I don't want to use ADODC , just an ADODB.Recordset

I have this code written but it didn't help me much

For the ComboBox

Dim rs_reg As ADODB.Recordset
Set rs_reg = New ADODB.Recordset
rs_reg.ActiveConnection = Conbase
rs_reg.Source = "SELECT MyTable.* FROM MyTable;"
rs_reg.Open , , 3, adLockOptimistic

Set Cmbgener.DataSource = rs_reg
Cmbgener.DataField = rs_reg!Field1
Cmbgener.Refresh

For the datagrid

Dim rs_data As ADODB.Recordset
Set rs_data = New ADODB.Recordset
rs_data.ActiveConnection = Conbase
rs_data.Source = "SELECT MyTable.* FROM MyTable;"
rs_data.Open , , 3, adLockOptimistic

Set Dg1.DataSource = rs_data
Dg1.Refresh


I have the datagrid and the combobox in different forms
Thanks
Schachmann
0
Comment
Question by:schachmann
[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
9 Comments
 
LVL 3

Expert Comment

by:RiverGuy
ID: 8104859
How about this for the combo box

Dim intCount As Integer
    rst1.MoveFirst
    Do Until rst1.EOF
        With Combo1
            .AddItem rst1![descriptionField]
            .ItemData(intCount) = rst1![IDField]
        End With
        intCount = intCount + 1
        rst1.MoveNext
    Loop
0
 
LVL 1

Author Comment

by:schachmann
ID: 8106447
RiverGuy:
i need to use datasource. I know that code you typed.
And how about the datagrid? any suggestions?
0
 
LVL 3

Expert Comment

by:RiverGuy
ID: 8106531
You need to use the datasource?  Why?  Are you wanting to bind this to lookup from one table and to change data in another table?  Have you thought about using a DataCombo?
0
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!

 
LVL 11

Accepted Solution

by:
supunr earned 160 total points
ID: 8106814
You can not bind a recordset to a combo box.  If you want to do that, then you have to use "Microsoft DataList Controls 6.0" and have a modular recordset open.  Otherwise, you have to manually add the records for the combo box.

To add records to combo box...

Dim rs_reg As ADODB.Recordset
Set rs_reg = New ADODB.Recordset
rs_reg.ActiveConnection = Conbase
rs_reg.Source = "SELECT MyTable.* FROM MyTable;"
rs_reg.Open , , 3, adLockOptimistic

combo1.Clear ' remove all items
if (re_reg.RecordCount > 0) then rs_reg.MoveFirst
Do While (NOT rs_reg.EOF)
     Cmbgener.AddItem rs_reg.Fields("FieldName").Value
     rs_reg.MoveNext
Loop

However if you use data combo, then you only have to say...
Set DataCombo1.RowSource = rs_reg
' but make sure the rs_reg is open at this point and it is open during the whole process.

For datagrid, I found that if the recordset contains no records, the grid behaves strangly after refreshing.  So make sure to check if the recordcount is > 0

Set Dg1.DataSource = Nothing
Dg1.ClearFields
if (rs_data.RecordCount > 0) then
     Set Dg1.DataSource = rs_data
End if
0
 
LVL 1

Author Comment

by:schachmann
ID: 8107130
supunr:
I tried your code. I tried to connect the database with ADO and it work fine. But when i try to do it with adodb y don't get any records. And i checked for recordcount and it is bigger than 0. Any ideas?
Thanks again
schachmann
0
 
LVL 1

Author Comment

by:schachmann
ID: 8107144
Sorry!
i solved the combo stuff. I did what you said RiverGuy and supunr and worked. I thought you could do it the same way with combobox and datacombo.
The problem is with the datagrid
0
 
LVL 3

Assisted Solution

by:RiverGuy
RiverGuy earned 140 total points
ID: 8107306
0
 
LVL 1

Author Comment

by:schachmann
ID: 8657106
HI!
i´ve splitted the points.
check the link for additional info.
http://www.experts-exchange.com/Community_Support/Q_20637996.html
Thanks to both of you
0
 

Expert Comment

by:SpideyMod
ID: 8659451
schachmann,
You can split the points yourself now.  Look just above the comment area, there is a link called "Spilt"  Click it and follow the prompts.

SpideyMod
Community Support Moderator @Experts Exchange
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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

752 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