Results 1 to 4 of 4
  1. #1
    Pontus is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jul 2015
    Posts
    5

    List box category disappears after clicking in text box

    Hello! I just started working with Access 2013 trying to build a searchable database, but now I have a problem with a list box. I used the list box wizard to setup the list. I also imported all the categories for the list from a table.

    When I view my form everyting looks good but as soon as I click in a text box which I am using as a searchfield some of the categories disappears from the list box and all of the others makes a jump to the left leaving the right side just gray.

    I tried to google this problem but no results showed up. I would be super thankful I anyone could give me some advice!
    Thanks in advance!
    Click image for larger version. 

Name:	Accesslistbox.png 
Views:	18 
Size:	80.3 KB 
ID:	21266

    I found this code via a youtuber named "ibasskung":

    Option Compare Database
    Private Sub Form_Load()
    txtSearch.SetFocus


    End Sub
    Private Sub Frame2_AfterUpdate()
    txtSearch = ""
    txtSearch.SetFocus
    End Sub
    Private Sub cmdClose_Click()
    DoCmd.Close acForm, "Form1"
    'Close Form1
    End Sub
    Private Sub txtSearch_Change()
    If Frame2 = 1 Then 'Manufacturer
    strRowsource = "SELECT [Manufacturer],[RatedCurrent],[RatedVoltage],[BIL],[TotalLength],[CatNO] " & "FROM BushingsT " & _
    "WHERE [Manufacturer]Like '*" & Me.txtSearch.Text & "*' "
    ElseIf Frame2 = 2 Then 'RatedCurrent
    strRowsource = "SELECT [Manufacturer],[RatedCurrent],[RatedVoltage],[BIL],[TotalLength],[CatNO] " & "FROM BushingsT " & _
    "WHERE [RatedCurrent]Like '*" & Me.txtSearch.Text & "*' "
    ElseIf Frame2 = 3 Then 'RatedVoltage
    strRowsource = "SELECT [Manufacturer],[RatedCurrent],[RatedVoltage],[BIL],[TotalLength],[CatNO] " & "FROM BushingsT " & _
    "WHERE [RatedVoltage]Like '*" & Me.txtSearch.Text & "*' "
    ElseIf Frame2 = 4 Then 'BIL
    strRowsource = "SELECT [Manufacturer],[RatedCurrent],[RatedVoltage],[BIL],[TotalLength],[CatNO] " & "FROM BushingsT " & _
    "WHERE [BIL]Like '*" & Me.txtSearch.Text & "*' "
    Else 'TotalLength
    strRowsource = "SELECT [Manufacturer],[RatedCurrent],[RatedVoltage],[BIL],[TotalLength],[CatNO] " & "FROM BushingsT " & _
    "WHERE [TotalLength]Like '*" & Me.txtSearch.Text & "*' "
    End If
    List16.RowSource = strRowsource
    End Sub
    Private Sub txtSearch_Click()
    strRowsource = "SELECT [Manufacturer],[RatedCurrent],[RatedVoltage],[BIL],[TotalLength], CatNO " & "FROM BushingsT"
    List16.RowSource = strRowsource
    End Sub

  2. #2
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    Your code would be a lot easier to read if you used the code tags (the # button) to preserve spacing and indentation

    it is because you are only selecting these fields

    SELECT [Manufacturer],[RatedCurrent],[RatedVoltage],[BIL],[TotalLength],[CatNO]
    you can also significantly simplify your code

    Code:
    Private Sub txtSearch_Change()
        List16.RowSource = "SELECT [Manufacturer],[RatedCurrent],[RatedVoltage],[BIL],[TotalLength],[CatNO] " & "FROM BushingsT " & _
            "WHERE " & Choose(Frame2,"[Manufacturer]","[RatedCurrent]","[RatedVoltage]","[BIL]","[TotalLength]") & " Like '*" & Me.txtSearch.Text & "*'"
    End Sub
    or

    Code:
    Private Sub Frame2_AfterUpdate()
        txtSearch = ""
        txtSearch.SetFocus
        List16.RowSource = "SELECT [Manufacturer],[RatedCurrent],[RatedVoltage],[BIL],[TotalLength],[CatNO] " & "FROM BushingsT " & _
            "WHERE " & Choose(Frame2,"[Manufacturer]","[RatedCurrent]","[RatedVoltage]","[BIL]","[TotalLength]") & " Like '*" & Me.txtSearch.Text & "*'"
     End Sub
    
    Private Sub txtSearch_Change()
        List16.requery
    End Sub

  3. #3
    Pontus is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jul 2015
    Posts
    5
    Quote Originally Posted by Ajax View Post
    Your code would be a lot easier to read if you used the code tags (the # button) to preserve spacing and indentation

    it is because you are only selecting these fields



    you can also significantly simplify your code

    Code:
    Private Sub txtSearch_Change()
        List16.RowSource = "SELECT [Manufacturer],[RatedCurrent],[RatedVoltage],[BIL],[TotalLength],[CatNO] " & "FROM BushingsT " & _
            "WHERE " & Choose(Frame2,"[Manufacturer]","[RatedCurrent]","[RatedVoltage]","[BIL]","[TotalLength]") & " Like '*" & Me.txtSearch.Text & "*'"
    End Sub
    or

    Code:
    Private Sub Frame2_AfterUpdate()
        txtSearch = ""
        txtSearch.SetFocus
        List16.RowSource = "SELECT [Manufacturer],[RatedCurrent],[RatedVoltage],[BIL],[TotalLength],[CatNO] " & "FROM BushingsT " & _
            "WHERE " & Choose(Frame2,"[Manufacturer]","[RatedCurrent]","[RatedVoltage]","[BIL]","[TotalLength]") & " Like '*" & Me.txtSearch.Text & "*'"
     End Sub
    
    Private Sub txtSearch_Change()
        List16.requery
    End Sub
    Thanks for the reply!

    I don't quite understand what you mean. Am I only selecting one of the categories? Anyways I solved it in another way, by first showing the ID (AutoNumber) and when clicking in the text field the ID disappears.
    Last edited by Pontus; 07-15-2015 at 03:01 AM. Reason: Spelling

  4. #4
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    I must have misunderstood your question

    Good luck with your project

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 05-10-2014, 09:24 AM
  2. Replies: 9
    Last Post: 04-25-2014, 12:33 PM
  3. Replies: 5
    Last Post: 04-24-2013, 08:50 AM
  4. Replies: 14
    Last Post: 02-19-2013, 03:16 PM
  5. Replies: 2
    Last Post: 10-12-2010, 12:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums