Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc,microsoft.public.excel.newusers,microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Combobox or Listbox

Can a combobox and a listbox on a userform get their list items from a query or
table in an Access database? How?

Thanks,

Kathy


  #2   Report Post  
Posted to microsoft.public.excel.misc,microsoft.public.excel.newusers,microsoft.public.excel.programming
external usenet poster
 
Posts: 1,089
Default Combobox or Listbox

Kathy

please do not cross-post. The same people tend to look at all the groups so
you won't get more answers, just more irritated volunteers

Regards

Trevor


"Kathy" wrote in message
ink.net...
Can a combobox and a listbox on a userform get their list items from a

query or
table in an Access database? How?

Thanks,

Kathy




  #3   Report Post  
Posted to microsoft.public.excel.misc,microsoft.public.excel.newusers,microsoft.public.excel.programming
external usenet poster
 
Posts: 459
Default Combobox or Listbox

This code selects two columns, a key and a column respectively. The
key is shown in the combo's first (hidden) column, the data in its
second (visible) column. I've used appropriate recordset settings in
case you want to be able to update the source.

'-----------------------
Option Explicit
Private Sub UserForm_Initialize()

Dim m_oConn As Object
Dim m_oRS As Object

Const strCONNECTION As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source="
Const strPATH As String = "C:\Tempo\New_Jet_DB.mdb"
Const strSQL As String = "SELECT RefID, Surname FROM PersonalDetails"

Dim vntArray As Variant

Set m_oConn = CreateObject("ADODB.Connection")
m_oConn.Open strCONNECTION & strPATH

Set m_oRS = CreateObject("ADODB.Recordset")

With m_oRS
.CursorLocation = 3 ' adUseClient
.CursorType = 3 ' adOpenStatic
.LockType = 4 ' adLockBatchOptimistic
.ActiveConnection = m_oConn
.Command = strSQL
.Open
End With

With ComboBox1

.ColumnCount = 2
.BoundColumn = 1
.TextColumn = 2
.ColumnWidths = "0;" ' first column invisible

vntArray = m_oRS.GetRows
.List = Application.Transpose(vntArray)

End With

End Sub

'----------------------

"Trevor Shuttleworth" wrote in message ...
Kathy

please do not cross-post. The same people tend to look at all the groups so
you won't get more answers, just more irritated volunteers

Regards

Trevor


"Kathy" wrote in message
ink.net...
Can a combobox and a listbox on a userform get their list items from a

query or
table in an Access database? How?

Thanks,

Kathy


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Combobox/Listbox Difference WLMPilot Excel Discussion (Misc queries) 1 November 21st 06 01:46 PM
Combobox v Listbox MBlake New Users to Excel 5 April 24th 05 11:58 AM
Combobox/listbox FSt1 Excel Discussion (Misc queries) 3 January 4th 05 06:55 PM
listbox.value not equal to listbox.list(listbox.listindex,0) ARB Excel Programming 0 October 22nd 03 12:46 AM
listbox-combobox category GUS Excel Programming 1 September 12th 03 04:52 PM


All times are GMT +1. The time now is 08:46 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"