Hi All,
How to display data in the listbox column header.
Please send the VBA code.
Thanks in advance..!
Mangai Venkata
Hi All,
How to display data in the listbox column header.
Please send the VBA code.
Thanks in advance..!
Mangai Venkata
Re: How to display data in the listbox column header
1. Get data of your choosing
2. Display in ListBox (specifically, the header column)
Based on your post - that's about as specific the help is going to get. Try giving an actual example of what you're trying to achieve, and at least try Google or search within this forum first before asking someone for a complete code example.
P.S. A couple more scrolls down the page will show you the answer anyway.
Re: How to display data in the listbox column header
Hi,
Thank you for the reply..
Please find the attachment as a sample with the listbox where header column should hold the column name..
[ATTACH=CONFIG]69329[/ATTACH]
Thanks..
Mangai Venkata
Re: How to display data in the listbox column header
That's a picture of a user form with a listBox control on it.
It doesn't tell us anything. Please put the effort into your question that you expect others to put into their answers.
Re: How to display data in the listbox column header
Hi,
Please find the below code:
Private Sub cmdAppend_Click()
'Declaring the necessary variables.
Dim cnn As ADODB.Connection 'dim the ADO collection class
Dim rs As ADODB.Recordset 'dim the ADO recordset class
Dim dbPath As String
Dim i As Integer
Dim x As Integer
'add error handling
On Error GoTo errHandler:
If Me.Arec1.Value = "" Then
MsgBox "You must enter a valid ID number.", _
vbOKOnly Or vbInformation, "Insufficent data"
Exit Sub
End If
'get the path to the database
dbPath = Sheet1.Range("I3").Value
Set cnn = New ADODB.Connection ' Initialise the collection class variable
'Connection class is equipped with a —method— named Open
'—-4 aguments—- ConnectionString, UserID, Password, Options
'ConnectionString formula—-Key1=Value1;Key2=Value2;Key_n=Value_n;
cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & dbPath
Set rs = New ADODB.Recordset 'assign memory to the recordset
'Create the SQL statement to retrieve the data from table.
rs.Open "SELECT * FROM PhoneList " & _
"WHERE ID = " & CLng(Me.Arec1), ActiveConnection:=cnn, _
CursorType:=adOpenDynamic, LockType:=adLockOptimistic, _
Options:=adCmdText
If rs.EOF And rs.BOF Then
'Close the recordet and the connection.
rs.Close
cnn.Close
'clear memory
Set rs = Nothing
Set cnn = Nothing
'Enable the screen.
Application.ScreenUpdating = True
'In case of an empty recordset display an error.
MsgBox "There are no records in the recordset!", vbCritical, "No Records"
Exit Sub
End If
With rs
For i = 1 To 7
rs(Cells(1, i).Value) = Me.Controls("Arec" & i).Value
Next i
rs.Update
End With
'clear the userform values
For x = 1 To 7
Me.Controls("Arec" & x).Value = ""
Next
'Close the recordset and the connection.
rs.Close
cnn.Close
'clear memory
Set rs = Nothing
Set cnn = Nothing
'refresh the listbox
ImportUserForm
'Enable the screen.
Application.ScreenUpdating = True
Me.lstDataAccess.RowSource = "DataAccess"
'Inform the user that the macro was executed successfully.
MsgBox "Congratulation the data has been appended", vbInformation, "Append successful"
'error handler
On Error GoTo 0
Exit Sub
errHandler:
'clear memory
Set rs = Nothing
Set cnn = Nothing
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Import_Data"
End Sub
Display More
where listbox control lstDataAccess name populate the data & that where i am trying to display in column header.
Please help.
thanks..
Mangai Venkata
______________________________________________________________________________________________________
[COLOR="#FF0000"]Mod Edit[/COLOR]:
Please use Code tags when you post code in a message. As you can see, Code Tags format the code making it easier to read and follow the logic. Code tags are added when ediitng a message, simply highlight the code and click the '#' button on the toolbar above the Edit box.
Re: How to display data in the listbox column header
ColumnHeaders can only be displayed if the RowSource is from a Worksheet range. The ColumnHeaders will be taken from the row above the first row of the range used for RowSource. You cannot display Column Headers if the Rowsource is a RecordSet object.
General answer only - you did not include the code for the Procedure ImpoerUserForm and I've no idea what "DataAccess" is in the following code snippet
Re: How to display data in the listbox column header
thank you for your reply & time as well...
I was looking at this problem just now and found this solution. If your RowSource points to a range of cells, the column headings in a multi-column listbox are taken from the cells immediately above the RowSource.
But if i choose through listbox properties as column heads it loads header but i am not able to interconnect this.
Re: How to display data in the listbox column header
Quote from Mangai Venkata...the column headings in a multi-column listbox are taken from the cells immediately above the RowSource
Quote from cytopColumnHeaders can only be displayed if the RowSource is from a Worksheet range ... will be taken from the row above the first row of the range used for RowSource
Spot the difference.
Re: How to display data in the listbox column header
thanks again...no differences..its the same but i am trying to use columnheads property..
Where the problem is...data is getting displayed in the second row not in the first especially in the column header...
i would be happy if you spot the issue whether i have to code it separately to get into the first row..
listbox data not through rowsource in case..
please help..
Don’t have an account yet? Register yourself now and be a part of our community!