S
sebastico
Hello
In a Form I have a list box to display NameID and Name fields. I also have
buttons for each letter form A to Z. The idea is If I click a button the
listbox displays all names starting with such letter.
Also I have a button to show all the names and another to clean the listbox
names.
When I open the Form it shows all names, so I don't know if the button All
works.
When I click the Clean button nothing happens.
When I click the A button it shows Compile Error: Sub or Function not
defined. Also code Left (Name, 1) = 'A'; " is red in colour.
This is my code
Option Compare Database
Option Explicit
'Here CmdA will display in Listbox all names starting with A
Private Sub CmdA_Click()
lsbNames.RowSource = "SELECT NameID, Name FROM TNames"
WHERE
Left(Nomb, 1) = 'A';"
End Sub
'Clean names in listbox
Private Sub CmdClean_Click()
Dim l As Long
For l = 0 To lsbNames.ListCount - 1
lsbNames.Selected(l) = False
Next
End Sub
'To show all Names
Private Sub CmdAll_Click()
lsbNames.RowSource = "SELECT NameID, Name FROM TNames;"
End Sub
I don't know What I, doing wrong
Could you tell me how to fix my code? I'm learning how to program in vba by
myself and with the forum, so I would really appreciate your help.
Many thanks
In a Form I have a list box to display NameID and Name fields. I also have
buttons for each letter form A to Z. The idea is If I click a button the
listbox displays all names starting with such letter.
Also I have a button to show all the names and another to clean the listbox
names.
When I open the Form it shows all names, so I don't know if the button All
works.
When I click the Clean button nothing happens.
When I click the A button it shows Compile Error: Sub or Function not
defined. Also code Left (Name, 1) = 'A'; " is red in colour.
This is my code
Option Compare Database
Option Explicit
'Here CmdA will display in Listbox all names starting with A
Private Sub CmdA_Click()
lsbNames.RowSource = "SELECT NameID, Name FROM TNames"
WHERE
Left(Nomb, 1) = 'A';"
End Sub
'Clean names in listbox
Private Sub CmdClean_Click()
Dim l As Long
For l = 0 To lsbNames.ListCount - 1
lsbNames.Selected(l) = False
Next
End Sub
'To show all Names
Private Sub CmdAll_Click()
lsbNames.RowSource = "SELECT NameID, Name FROM TNames;"
End Sub
I don't know What I, doing wrong
Could you tell me how to fix my code? I'm learning how to program in vba by
myself and with the forum, so I would really appreciate your help.
Many thanks