Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2009
    Location
    Gatineau, Quebec Canada
    Posts
    147
    Provided Answers: 1

    Unanswered: List Box Behavior on click

    Hi,

    I have two list boxes -- subjects and teachers -- that I use to populate a third -- course units. All work via underlying tables, and SQL queries and deletions. I error check by ensuring that an item on both lists is always selected (eg. "lstTeachers.selected(0) = true"). I use the "onclick" event of the teachers list, but found that when when I clicked on either the "teachers" or the "subjects" box, it updated the third.

    Why is it when I click on the subject list, it acts as if I clicked on the teachers box (i.e. was triggering the lstTeachers_onClick event)? I use Access 2003. BTW, the problem was resolved when I went to the double click event.

    Regards

    John S
    Guangxi U.
    Nanning China.

  2. #2
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    I suspect the reason you've had no response, after the better part of a day, is that your post is very unclear.
    Quote Originally Posted by praxis1949 View Post
    I error check by ensuring that an item on both lists is always selected (eg. "lstTeachers.selected(0) = true")
    How does this line provide any error checking? Where is it placed?

    Quote Originally Posted by praxis1949 View Post
    All work via underlying tables, and SQL queries and deletions...Why is it when I click on the subject list, it acts as if I clicked on the teachers box (i.e. was triggering the lstTeachers_onClick event)?
    How do you expect anyone to explain why your code is behaving in the manner you describe if we cannot see your code? We are frequently out of our minds, here, but this does not mean that we can read your mind!

    And lastly, are you in China, as your post says, or in Canada, as your profile says?
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  3. #3
    Join Date
    Mar 2009
    Location
    Gatineau, Quebec Canada
    Posts
    147
    Provided Answers: 1

    Listboxes

    Hi. Good points. I thought there was some kind of known problem with list boxes, and thus did not attach the code. It is below. I live in Canada, but am temporarily teaching English in Nanning, China.

    Code:

    Private Sub lstTeacher_DblClick(Cancel As Integer)
    Dim aString As String
    Dim aCount As Integer


    If Me.lstSubject.ListIndex = -1 Then
    MsgBox "You must choose an exam!", , "Guangxi University"
    Me.lstSubject.SetFocus
    Else


    aString = Me.lstSubject.Column(1) & "---" & Me.lstTeacher.Column(1)


    Dim currCon As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    Dim rs2 As New ADODB.Recordset
    Set currCon = CurrentProject.Connection
    DoCmd.SetWarnings False

    aSQL = "INSERT INTO t_tblInvig (Invig, sub, tea) VALUES ('" & aString & "', " & Me.lstSubject.Column(0) & "," & Me.lstTeacher.Column(0) & ")"
    DoCmd****nSQL (aSQL)
    aSQL = "DELETE * FROM t_tblCourse WHERE ID = " & Me.lstSubject.Column(0)
    DoCmd****nSQL (aSQL)
    aSQL = "DELETE * FROM t_tblTeacher WHERE ID = " & Me.lstTeacher.Column(0)
    DoCmd****nSQL (aSQL)



    Me.lstAll.Requery
    Me.lstSubject.Requery

    ' reload teachers list box if empty

    If IsNull(DLookup("ID", "t_tblTeacher")) Then

    aSQL = "SELECT ID, NAME FROM tblTeacher"

    rs2.Open aSQL, currCon, adOpenForwardOnly
    rs2.MoveFirst
    Do While Not rs2.EOF
    aSQL2 = "INSERT INTO t_tblTeacher ( ID,NAME ) VALUES (" & rs2("ID") & ", '" & rs2("NAME") & "' ) "
    DoCmd****nSQL (aSQL2)
    rs2.MoveNext
    Loop


    End If

    Me.lstTeacher.Requery

    DoCmd.SetWarnings True

    currCon.Close

    ' select items from subject, list box

    Me.lstTeacher.Selected(0) = True
    Me.lstSubject.Selected(0) = True

    ' prevents selection of last item on reload

    Me.lstTeacher.Selected(teacherCount - 1) = False




    End If


    End Sub

  4. #4
    Join Date
    Mar 2009
    Location
    Gatineau, Quebec Canada
    Posts
    147
    Provided Answers: 1
    BTW, this line is not in use: sorry: "Me.lstTeacher.Selected(teacherCount - 1) = False "

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •