473,405 Members | 2,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,405 developers and data experts.

AddAllToList With Column Headers

Denburt
1,356 Expert 1GB
This function was originally created back in the dawn of time, over the years I have made a number of changes and after searching the net I still didn't see 1 that allowed for the use of column headers so I thought I would post one that does.

On the controls property simply click yes or no for Column Headers and off you go.

You can use the Tag property to determine the column and the words displayed.
2;<No Selection>

To help save a click this Function will also select the Item in the list that you just added, this is commented in the lower portion of the function in case you decide to remove it.

If you need further information on the implementation of this function you can find that here:
http://support.microsoft.com/kb/128881


Expand|Select|Wrap|Line Numbers
  1. Function AddAllToList(ctl As Control, lngID As Long, lngRow As Long, _
  2. lngCol As Long, intCode As Integer) As Variant
  3. On Error GoTo Err_AddAllToList
  4.       Static dbs As Database, rst As Recordset
  5.       Static lngDisplayID As Long
  6.       Static intDisplayCol As Integer
  7.       Static strDisplayText As String
  8.       Static ctlVal As String
  9.       Dim intSemiColon As Integer
  10.       Select Case intCode
  11.          Case acLBInitialize
  12.             If lngDisplayID <> 0 Then
  13.                MsgBox "AddAllToList is already in use by another control!"
  14.                AddAllToList = False
  15.                Exit Function
  16.             End If
  17.             If ctl.Tag > "" Then
  18.                 intSemiColon = InStr(ctl.Tag, ";")
  19.                If intSemiColon = 0 Then
  20.                   intDisplayCol = Val(ctl.Tag)
  21.                Else
  22.                   intDisplayCol = Val(Left(ctl.Tag, intSemiColon - 1))
  23.                   strDisplayText = Mid(ctl.Tag, intSemiColon + 1)
  24.                End If
  25.             Else
  26.                 intDisplayCol = 1
  27.                 strDisplayText = "(All)"
  28.             End If
  29.             ctlVal = strDisplayText
  30.             Set dbs = CurrentDb
  31.             Set rst = dbs.OpenRecordset(ctl.RowSource, dbOpenSnapshot)
  32.             lngDisplayID = Timer
  33.             AddAllToList = lngDisplayID
  34.          Case acLBOpen
  35.             AddAllToList = lngDisplayID
  36.          Case acLBGetRowCount
  37.             On Error Resume Next
  38.             rst.MoveLast
  39.             If ctl.ColumnHeads = True Then
  40.                 AddAllToList = rst.RecordCount + 2
  41.             Else
  42.                 AddAllToList = rst.RecordCount + 1
  43.             End If
  44.          Case acLBGetColumnCount
  45.             AddAllToList = rst.Fields.Count
  46.          Case acLBGetColumnWidth
  47.             AddAllToList = -1
  48.          Case acLBGetValue
  49.             If ctl.ColumnHeads = True Then
  50.                 If lngRow = 0 Then
  51.                         AddAllToList = rst.Fields(lngCol).Name
  52.                 ElseIf lngRow = 1 Then
  53.                     If lngCol = intDisplayCol - 1 Then
  54.                         AddAllToList = strDisplayText
  55.                     Else
  56.                         AddAllToList = Null
  57.                     End If
  58.                 Else
  59.                     rst.MoveFirst
  60.                     rst.Move lngRow - 2
  61.                     AddAllToList = rst(lngCol)
  62.                 End If
  63.             Else
  64.                 If lngRow = 0 Then
  65.                     If lngCol = intDisplayCol - 1 Then
  66.                         AddAllToList = strDisplayText
  67.                     Else
  68.                         AddAllToList = Null
  69.                     End If
  70.                 Else
  71.                     rst.MoveFirst
  72.                     rst.Move lngRow - 1
  73.                     AddAllToList = rst(lngCol)
  74.                 End If
  75.             End If
  76.          Case acLBEnd
  77.             lngDisplayID = 0
  78.             rst.Close
  79. 'The following if statement selects the item in the list that you have just added
  80.             If ctlVal <> "" Then
  81.                 ctl.Value = ctlVal
  82.             End If
  83.             Set rst = Nothing
  84.             Set dbs = Nothing
  85.       End Select
  86. Bye_AddAllToList:
  87.       Exit Function
  88.  
  89. Err_AddAllToList:
  90.     MsgBox Err.Description, vbOKOnly + vbCritical, "AddAllToList"
  91.     AddAllToList = False
  92.     Resume Bye_AddAllToList
  93. End Function
May 7 '09 #1
1 4643
FishVal
2,653 Expert 2GB
Almost the same: MS Access Calculated List
May 8 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: jburda | last post by:
I have set up a query where I am using a cursor to pass result from one query to use as select parameters in another query. The problem I am having is that when I pass the results into the second...
2
by: Yaron | last post by:
Hi I'm creating a control very similar to the ListView in Details mode. I'm confused as to how to go about drawing the column headers at the top As the column headers are static and stay in one...
2
by: MFRASER | last post by:
I am trying to populate a listview and I can not see the column headers, is there a property I am forgetting to set? Here is my code // Create three items and three sets of subitems for each...
2
by: David Veeneman | last post by:
How can I set a bound DataGridView control to use a dataset table's column captions, instead of column names? I'm working with a DataGridView control, which I have bound to a table in a dataset....
4
by: Hans Merkl | last post by:
Hi, Is there a way to show the column headers of a GridView control even if there is no data? The only thing I see is the EmptyDataTemplate but I would also like to display the column headers. ...
1
by: ElenaR | last post by:
I need to figure out how to name my column headers in a DataGrid. In VB6, I could write DataGrid1.Columns(0).Caption = "ID". What is the format for VB.NET? Thanks in Advance!
2
by: John Walker | last post by:
Hi, We have a datagrid with column headers. If the datagrid has more than say 25 rows the user needs to scroll down to be able to see the rest of the grid. When the user does this the column...
4
by: Markus Ernst | last post by:
Hi Looking for a possibility to get separate tables rendered with common column widths, I was surprised to see that this code validates: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"...
4
by: SKelso | last post by:
I created a database in Access 2003 that contains an unbound search form with several combo boxes. Each combo box is populated with entries from the appropriate table. I want to allow the user to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.