• Code help for Listbox (2000)

    Author
    Topic
    #438661

    Edited by HansV to break up very long line

    I have a form with 2 multi-select listboxes. The first listbox controls what will be seen in the second.
    This part works OK. The problem is that I have a Reset function that resets both listboxes to a default setting.

    Private Function Reset()
    Dim strSQL As String
    Me.cboRegions = "*"
    g_Region = "*"
    Me.cboTech = "*"
    g_Tech = "*"
    Me.cboTeam = "*"
    g_Team = "*"
    Me.cboTech.Requery
    Me.cboTeam.Requery
    Me.cboRegions.Visible = True
    Me.Regions_Label.Visible = True
    Me.cboTech.Visible = True
    Me.TECH_Label.Visible = True
    Me.cboTeam.Visible = True
    Me.lstRank = "*"
    Me.lstRank.SetFocus
    Me.lstRank.ListIndex = 0
    g_Rank = "*"
    Me.lstChannel = "*"
    Me.lstChannel.SetFocus
    Me.lstChannel.ListIndex = 0
    g_Channel = "*"
    Me.lstBrand = "*"
    Me.lstBrand.SetFocus
    Me.lstBrand.ListIndex = 0
    g_Brand = "*"
    Me.lstActivity = "*"
    Me.lstActivity.SetFocus
    Me.lstActivity.ListIndex = 0
    g_ActivityCode = "*"
    'code for Result listbox source
    strSQL = "SELECT tblResultCode.Description FROM tblResultCode " & _
    "WHERE ((([tblResultCode].[Activity]) Like '*')) UNION SELECT ' * ' as " & _
    "Bogus from tblResultCode;"
    Me.lstResult.RowSource = strSQL
    Me.lstResult.Requery
    
    Me.lstResult = "*"
    Me.lstResult.SetFocus 'Line that gets the error
    Me.lstResult.ListIndex = 0
    g_ResultCode = "*"
    
    Me.cmdExit.SetFocus
    End Function

    On the line Me.lstResult.SetFocus, I get a message “Access can’t move the focus to the control lstResult.
    I tried moving the focus to another item on the form then back with no help.
    Scott

    Viewing 0 reply threads
    Author
    Replies
    • #1046484

      Is lstResult visible? If not, you cannot set the focus to it. If you want to set focus to it, you should make it visible first.

      • #1046488

        Sorry, I asked for help too soon.
        I found a bit of code in the previous listbox that still had control.
        Scott

        • #1046713

          I’ve run into another problem with the listbox. It seems that after resetting the listboxes, you have to click twice on any other control to activate it.
          My guess is the first click gets you out of the first listbox and the second click actually activates whatever you click on.
          I included a stripped down version with the offending listboxes and a couple of other items to click on.
          Can someone see why its getting stuck?
          Thanks,
          Scott

          • #1046719

            I cannot reproduce the error, but I noticed several problems with the code – I got lots of error messages when I tried to open the database. The attached version avoids those.

            • #1046730

              Hans,
              As always, Thank you.
              I see I was using the listbox properties wrong.

    Viewing 0 reply threads
    Reply To: Code help for Listbox (2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: