Wrox Programmer Forums
|
BOOK: Excel 2007 VBA Programmer's Reference ISBN: 978-0-470-04643-2
This is the forum to discuss the Wrox book Excel 2007 VBA Programmer's Reference by John Green, Stephen Bullen, Rob Bovey, Michael Alexander; ISBN: 9780470046432
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Excel 2007 VBA Programmer's Reference ISBN: 978-0-470-04643-2 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 16th, 2010, 09:23 AM
Registered User
 
Join Date: Feb 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Listbox data from Access

Hi guys

I'm making a Excel ADD-In application for a knowlede database at my work. All the data is located in an Access database and handled by a frontend in Excel (managed by ADO)

On page 282 in the book you write: "It is really much easier to maintain a data list in a proper database application, such as Microsoft Access"

How do you do that?

Until now I have put the data from Acces into a sheet and refered to it by the listbox rowsource property. And It worked fine in the .xls but when I create the ADD-In I can't get any data in the listbox. It is empty

Is there a simpler better way to do it?

Private Sub cbIdeData_Enter()

On Error GoTo FejlBehandler

'Åben forbindelse til Acces
Dim adoconn As ADODB.Connection
Dim adors As ADODB.Recordset
Dim sql As String
Dim filenm As String

sql = "Select * from IdeDB"
filenm = DBsti

Call GlobaleProcedurer.GetCn(adoconn, adors, sql, filenm, "", "")

Dim xlsht As Excel.Worksheet
Set xlsht = Workbooks("AluCoreBobleTank.xla").Sheets("Sheet3")
xlsht.Range("A1").CopyFromRecordset adors

adors.Close
adoconn.Close
Set adors = Nothing
Set adoconn = Nothing

Dim ListRange As Range
Set ListRange = Workbooks("AluCoreBobleTank.xla").Sheets("sheet3") .Range("A1", Sheet3.Range("C65000").End(xlUp))

'Initialiser Listbox
With cbIdeData
.ColumnCount = 3
.ColumnWidths = 30
.RowSource = ListRange.Address
.ListIndex = 0
End With

Set xlsht = Nothing

Exit Sub
FejlBehandler:
Select Case Err
Case -2147352571 'Der er NULL værdi i Access tabellen
Resume Next
Case -2147217913 'Der skrives NULL værdi til Access tabellen
Resume Next
Case -2147217900 'Der er ikke angivet et id nr
Exit Sub
Case Else
MsgBox ("Programmet er afsluttet pga udefineret fejl: " & Err.Number & " - " & Err.Description)
Exit Sub
End





Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Several Data Connections for 1 Listbox??? lnickol22 Visual Basic 2005 Basics 3 February 12th, 2008 12:58 PM
Row data in listbox? DrConners Access VBA 1 June 8th, 2007 02:20 PM
ListBox.AddItem In Access 2000 tready Access VBA 3 August 17th, 2006 01:11 PM
access listbox in onchange event ozcyberus1 JSP Basics 0 September 6th, 2004 05:34 PM
Listbox being poplutaed with Access database. gisenberg VB.NET 2002/2003 Basics 5 July 23rd, 2004 08:20 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.