Results 1 to 6 of 6
  1. #1
    3 Star Lounger
    Join Date
    Nov 2001
    Location
    Atlanta, Georgia, USA
    Posts
    274
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Code help for Listbox (2000)

    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.

    <pre>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</pre>


    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

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Code help for Listbox (2000)

    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.

  3. #3
    3 Star Lounger
    Join Date
    Nov 2001
    Location
    Atlanta, Georgia, USA
    Posts
    274
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Code help for Listbox (2000)

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

  4. #4
    3 Star Lounger
    Join Date
    Nov 2001
    Location
    Atlanta, Georgia, USA
    Posts
    274
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Code help for Listbox (2000)

    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

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Code help for Listbox (2000)

    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.

  6. #6
    3 Star Lounger
    Join Date
    Nov 2001
    Location
    Atlanta, Georgia, USA
    Posts
    274
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Code help for Listbox (2000)

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

Posting Permissions

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