Solved

combo box add item

Posted on 2004-04-01
5
912 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
  • 2
  • 2
5 Comments
 
LVL 13

Expert Comment

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

Expert Comment

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

?
0
 

Author Comment

by:Shezad Ahmed
Comment Utility
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
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…

772 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

15 Experts available now in Live!

Get 1:1 Help Now