?
Solved

combo box add item

Posted on 2004-04-01
5
Medium Priority
?
920 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 1500 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

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…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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
Course of the Month10 days, 12 hours left to enroll

764 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