Welcome to Dream.In.Code
Become a VB Expert!

Join 137,388 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 2,122 people online right now. Registration is fast and FREE... Join Now!




Excel VBA Coding

 
Reply to this topicStart new topic

Excel VBA Coding, Coding userform to extract data from List

itrabohills
8 Oct, 2008 - 01:57 AM
Post #1

New D.I.C Head
*

Joined: 8 Oct, 2008
Posts: 2

Hi, I hope someone can help. I have created a listbox and populated this with specific information from an access database. When the data is populated some of the text is too long for the list box. I would like the user to select the required data and then once selected a new form appears with the text in full, for example, the user clicks on the asset name and it shows the following info in a sep. form: Asset Name, Description, owner etc etc. I have created the new form with the labels and text boxes, but I'm not sure how to code this. Hopefully someone out there can shed some light on this problem.

Code for current Form, which extracts data from Access Database
CODE

Private Sub cmdPopulate_Click()
Dim myConnection As Connection
Dim strConnection As String
Dim myData As New Recordset
Dim strSQL As String
Dim lbItem As Integer

Me.lbAssets.ColumnCount = 6
lbItem = 0


'This line defines the connection string
strConnection = "Provider=MSDAORA.1;Password=Arpprd123;User ID=READONLY;Data Source=APORTP1;Persist Security Info=True"

'This line defines the SQL command
strSQL = "select ASSETNAME, ASSETDISPLAYNAME, EXTERNALAPPID, STDNAME, DESCRIPTION, OWNERGUID from SIMSUPP.ADR_ASSETWITHSTD ORDER BY ASSETNAME"

myData.Open strSQL, strConnection, adOpenForwardOnly

'here we read the data
Do Until myData.EOF = True

    With Me.lbAssets
        .AddItem
        .List(lbItem, 0) = myData![ASSETNAME] & ""
        .List(lbItem, 1) = myData![ASSETDISPLAYNAME] & ""
        .List(lbItem, 2) = myData![ExternalAppID] & ""
        .List(lbItem, 3) = myData![STDNAME] & ""
        .List(lbItem, 4) = myData![Description] & ""
        .List(lbItem, 5) = myData![OWNERGUID] & ""
    End With

    lbItem = lbItem + 1
    myData.MoveNext
Loop




myData.Close

Set myData = Nothing
Set myConnection = Nothing

End Sub


Mod edit - Added code tags.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/5/08 02:13AM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month