Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

listview control selected item

Discussion in 'Information Technology' started by jkendrick75, Nov 4, 2005.

  1. jkendrick75

    jkendrick75
    Expand Collapse
    Guest

    i am wanting to set up a double click event that would take the item being
    doubleclicked will open up another form with some of the information from the
    list item that was double clicked. The following code is not working for
    this.
    -------------------------------------------------
    Private Sub lsvOpenOrders_DblClick()
    'Dim Variables
    Dim MyDB As DAO.Database
    Dim rstWorkOrder, rstWorkTypeID, rstDeptID, rstPlantID, rstPressID,
    rstToolID As DAO.Recordset
    Dim intWON, intWTID, intDeptID, intPlantID, intPressID, intToolID As Integer
    'Set Database and Recordset Variables
    Set MyDB = CurrentDb
    Set rstWorkOrder = MyDB.OpenRecordset("tblWorkOrders", dbOpenDynaset)
    Set rstWorkTypeID = MyDB.OpenRecordset("tblWorkType", dbOpenDynaset)
    Set rstDeptID = MyDB.OpenRecordset("tblDepartment", dbOpenDynaset)
    Set rstPlantID = MyDB.OpenRecordset("tblPlant", dbOpenDynaset)
    Set rstPressID = MyDB.OpenRecordset("tblPress", dbOpenDynaset)
    Set rstToolID = MyDB.OpenRecordset("tblTool", dbOpenDynaset)
    'Compare selected item information to table information.
    rstWorkTypeID.MoveFirst
    Do While rstWorkTypeID.EOF = False
    If
    lsvOpenOrders.ListItems.SelectedItem(lsvOpenOrders.SelectedItem.SubItem(3)) =
    rstWorkTypeID.Fields("ID").Value Then
    strWorkType = rstWorkTypeID.Fields("Type").Value
    GoTo Continue
    Else
    rstWorkTypeID.MoveNext
    End If
    Loop
    Continue:
    Debug.Print CInt(strWorkType)
    End Sub
    ---------------------------------------------
    Any ideas would be welcome
    thanks
     
  2. Loading...

    Similar Threads Forum Date
    How To Control The 5 Thieves? Questions and Answers Apr 7, 2016
    General Controlling Kaam (Lust) Hard Talk Apr 8, 2014
    USA Sikh Americans join Barack Obama in urging lawmakers on Gun Control Breaking News Mar 29, 2013
    Controversial SGPC Takes Control of Live Telecast at Bangla Sahib Hard Talk Feb 7, 2013
    USA Sikhs Join Gun Control Debate. Meet with Vice President Biden Breaking News Jan 16, 2013

  3. WhyIsDoug

    WhyIsDoug
    Expand Collapse
    Guest

    The ListView control does not have the most intuitive programming interface
    in the world. That's for sure

    You might try something like this:

    Private Sub lvwOpenOrders_DblClick()
    Dim rstWorkType As DAO.Recordset
    Dim strSQL As String
    Dim strLvwID As String

    strLvwID = Me.lvwOpenOrders.SelectedItem.SubItems(1)

    strSQL = "SELECT Type FROM tblWorkTypeIDs WHERE ID=" & strLvwID

    Set rstWorkType = CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot)

    If Not (rstWorkType.BOF And rstWorkType.EOF) Then
    MsgBox "Work Type Selected: " & rstWorkType!Type
    End If

    rstWorkType.Close

    Set rstWorkType = Nothing
    End Sub

    I ommitted a bunch of the other stuff you had for clarity.

    Also .... I would avoid searching for the Work Type using the looping
    technique you have in your code unless you intend to do something to every
    record in the Recordset as you look for your value. You should let Jet do the
    work for you since it will use a binary search against the index for ID it
    will find it a whole lot faster than your code will.

    If you insist on using the code you have written you should get rid of the
    "Goto Continue" statement and corresponding line label and use an "Exit Do"
    statement in it's place. The use of Goto can really make it hard to debug the
    "Spagetti Code" that results.

    If this answered your question. Please make sure to respond appropriatly
    when asked so that it will be marked as an answer.

    --
    WhyIsDoug?


    "jkendrick75" wrote:

    > i am wanting to set up a double click event that would take the item being
    > doubleclicked will open up another form with some of the information from the
    > list item that was double clicked. The following code is not working for
    > this.
    > -------------------------------------------------
    > Private Sub lsvOpenOrders_DblClick()
    > 'Dim Variables
    > Dim MyDB As DAO.Database
    > Dim rstWorkOrder, rstWorkTypeID, rstDeptID, rstPlantID, rstPressID,
    > rstToolID As DAO.Recordset
    > Dim intWON, intWTID, intDeptID, intPlantID, intPressID, intToolID As Integer
    > 'Set Database and Recordset Variables
    > Set MyDB = CurrentDb
    > Set rstWorkOrder = MyDB.OpenRecordset("tblWorkOrders", dbOpenDynaset)
    > Set rstWorkTypeID = MyDB.OpenRecordset("tblWorkType", dbOpenDynaset)
    > Set rstDeptID = MyDB.OpenRecordset("tblDepartment", dbOpenDynaset)
    > Set rstPlantID = MyDB.OpenRecordset("tblPlant", dbOpenDynaset)
    > Set rstPressID = MyDB.OpenRecordset("tblPress", dbOpenDynaset)
    > Set rstToolID = MyDB.OpenRecordset("tblTool", dbOpenDynaset)
    > 'Compare selected item information to table information.
    > rstWorkTypeID.MoveFirst
    > Do While rstWorkTypeID.EOF = False
    > If
    > lsvOpenOrders.ListItems.SelectedItem(lsvOpenOrders.SelectedItem.SubItem(3)) =
    > rstWorkTypeID.Fields("ID").Value Then
    > strWorkType = rstWorkTypeID.Fields("Type").Value
    > GoTo Continue
    > Else
    > rstWorkTypeID.MoveNext
    > End If
    > Loop
    > Continue:
    > Debug.Print CInt(strWorkType)
    > End Sub
    > ---------------------------------------------
    > Any ideas would be welcome
    > thanks
    >
    >
     
  4. jkendrick75

    jkendrick75
    Expand Collapse
    Guest

    Ok, will look into this. Was actually able to get it working to do what i
    need for right now. Once i get the rest of the forms and reports made for
    the database, then i'll come back and take another look at your code, to try
    and clean up mine.
    thanks again.

    "WhyIsDoug" wrote:

    > The ListView control does not have the most intuitive programming interface
    > in the world. That's for sure
    >
    > You might try something like this:
    >
    > Private Sub lvwOpenOrders_DblClick()
    > Dim rstWorkType As DAO.Recordset
    > Dim strSQL As String
    > Dim strLvwID As String
    >
    > strLvwID = Me.lvwOpenOrders.SelectedItem.SubItems(1)
    >
    > strSQL = "SELECT Type FROM tblWorkTypeIDs WHERE ID=" & strLvwID
    >
    > Set rstWorkType = CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot)
    >
    > If Not (rstWorkType.BOF And rstWorkType.EOF) Then
    > MsgBox "Work Type Selected: " & rstWorkType!Type
    > End If
    >
    > rstWorkType.Close
    >
    > Set rstWorkType = Nothing
    > End Sub
    >
    > I ommitted a bunch of the other stuff you had for clarity.
    >
    > Also .... I would avoid searching for the Work Type using the looping
    > technique you have in your code unless you intend to do something to every
    > record in the Recordset as you look for your value. You should let Jet do the
    > work for you since it will use a binary search against the index for ID it
    > will find it a whole lot faster than your code will.
    >
    > If you insist on using the code you have written you should get rid of the
    > "Goto Continue" statement and corresponding line label and use an "Exit Do"
    > statement in it's place. The use of Goto can really make it hard to debug the
    > "Spagetti Code" that results.
    >
    > If this answered your question. Please make sure to respond appropriatly
    > when asked so that it will be marked as an answer.
    >
    > --
    > WhyIsDoug?
    >
    >
    > "jkendrick75" wrote:
    >
    > > i am wanting to set up a double click event that would take the item being
    > > doubleclicked will open up another form with some of the information from the
    > > list item that was double clicked. The following code is not working for
    > > this.
    > > -------------------------------------------------
    > > Private Sub lsvOpenOrders_DblClick()
    > > 'Dim Variables
    > > Dim MyDB As DAO.Database
    > > Dim rstWorkOrder, rstWorkTypeID, rstDeptID, rstPlantID, rstPressID,
    > > rstToolID As DAO.Recordset
    > > Dim intWON, intWTID, intDeptID, intPlantID, intPressID, intToolID As Integer
    > > 'Set Database and Recordset Variables
    > > Set MyDB = CurrentDb
    > > Set rstWorkOrder = MyDB.OpenRecordset("tblWorkOrders", dbOpenDynaset)
    > > Set rstWorkTypeID = MyDB.OpenRecordset("tblWorkType", dbOpenDynaset)
    > > Set rstDeptID = MyDB.OpenRecordset("tblDepartment", dbOpenDynaset)
    > > Set rstPlantID = MyDB.OpenRecordset("tblPlant", dbOpenDynaset)
    > > Set rstPressID = MyDB.OpenRecordset("tblPress", dbOpenDynaset)
    > > Set rstToolID = MyDB.OpenRecordset("tblTool", dbOpenDynaset)
    > > 'Compare selected item information to table information.
    > > rstWorkTypeID.MoveFirst
    > > Do While rstWorkTypeID.EOF = False
    > > If
    > > lsvOpenOrders.ListItems.SelectedItem(lsvOpenOrders.SelectedItem.SubItem(3)) =
    > > rstWorkTypeID.Fields("ID").Value Then
    > > strWorkType = rstWorkTypeID.Fields("Type").Value
    > > GoTo Continue
    > > Else
    > > rstWorkTypeID.MoveNext
    > > End If
    > > Loop
    > > Continue:
    > > Debug.Print CInt(strWorkType)
    > > End Sub
    > > ---------------------------------------------
    > > Any ideas would be welcome
    > > thanks
    > >
    > >
     

Share This Page