Solved

combo box add item

Posted on 2004-04-01
5
918 Views
Last Modified: 2013-12-25
Hi all

I have 2 combobox where the items are being autopopulated from 2 different lookup tables

At runtime if I view items in combo1 everything ok
If I view items in combo2 it has items from combo1 and not from specific lookup

Close form
At runtime if I view items in combo2 everything ok
If I view items in combo1 it has items from combo2 not from specific lookup

Which ever Combobox I select first it populates theother combobox with the same item data.

The code below
Any help highly apprecaited
Shaz

Private Sub Form_Load()
Dim xlApp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
Set xlApp = CreateObject("Excel.Application")

Dim i As Integer
Dim TotalCellCount As Integer
Dim Selectcell As String


Set xlbook = xlApp.Workbooks.Open("c:\SIC Look Up Table.xls")


Set xlsheet = xlbook.Worksheets(1)


TotalCellCount = ActiveSheet.Range("A1").CurrentRegion.Rows.Count


For i = 1 To TotalCellCount

Range("A" & i).Select
Selectcell = Application.ActiveCell.Value
Combo1.AddItem Selectcell
Next i

Set xlbook = xlApp.Workbooks.Open("c:\SIC Look Up 4.xls")

Set xlsheet = xlbook.Worksheets(1)
TotalCellCount1 = ActiveSheet.Range("A1").CurrentRegion.Rows.Count
For p = 1 To TotalCellCount1

Range("A" & p).Select
Selectcell1 = Application.ActiveCell.Value
combo2.AddItem Selectcell1
Next p

Set xlApp = Nothing
Set xlbook = Nothing
Set xlsheet = Nothing

0
Comment
Question by:Shezad Ahmed
[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
  • 2
  • 2
5 Comments
 
LVL 13

Expert Comment

by:crazyman
ID: 10730949
Any code in your combo events eg:Click,Change etc..
0
 
LVL 13

Expert Comment

by:crazyman
ID: 10730958
Also
What is Range and Application
Instead of Application.ActiveCell.Value should it be xlApp.ActiveCell.Value

?
0
 

Author Comment

by:Shezad Ahmed
ID: 10731225
Hi Crazyman

If I change Application.ActiveCell.Value to  xlApp.ActiveCell.Value then  combo1 only fills with the first item in row a.
Range just moves down coulmn A and replaces i with the next number.

What I have noticed is a number of instances of excel.exe running. Could this be the cause. Maybe locking the excel spreadsheet.
Surely there should be only one instance running

I do not have any Click,Change etc..

Cheers
Shezad
0
 
LVL 5

Accepted Solution

by:
Alok-Agarwal earned 500 total points
ID: 10731403
Hi,

Before setting xlbook to  "SIC Look Up 4.xls" ensure that you have closed the workbook by using


Workbooks.close

Hope that helps.

Thanks
Alok
0
 

Author Comment

by:Shezad Ahmed
ID: 10732875
Thanks everyone
I placed workbooks.close before setting  "SIC Look Up 4.xls
And also I placed workbooks.close and xlapp.quit before I set to nothing

0

Featured Post

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Determine Range to Select 5 58
Best way to parse out a json string in VB6? 10 293
RUNRMTCMD from AS/400 13 101
Error with a code discussed on this page 5 39
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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…

730 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