Forum Discussion

Data2link's avatar
Data2link
Copper Contributor
May 04, 2022

If Statement on a list box?

Hello, Im hoping I can get some help with a statement I want to put on a list box. I am making a Key-checkout form. I have a listbox of key numbers. Employees can have more than one key assigned to them, so I made separate Text boxes for each key number. So first key- 2nd key-3rd key and so forth. What I want to do is have that one listbox check if the first key box is empty. If it is, the key number goes there, if not, then it goes to text box 2, and so forth. The code I have is below, but it puts out a syntax error. I dont know what is wrong, as its been years since I've even looked at access. I'm not sure if I'm putting it in the wrong place (Under event procedure for the listbox)? Any help will be greatly appreciated 🙂

 

=iF IsNull(Key1) Then Key1 = ListBox ElseIf IsNull(text86) Then text86 = ListBox ElseIf IsNull(text103) Then text103 = ListBox ElseIf IsNull(text105) Then text105 End If

This brings back a invalid Syntax error

    • Data2link's avatar
      Data2link
      Copper Contributor

      RichardRost 

       

      Ok thank you so much. I will try that. I should be putting this under the listbox event correct?

      • RichardRost's avatar
        RichardRost
        MVP
        The list box's AfterUpdate event, yes. And I'd rename the list box to something like KeyList, and name those text boxes something better as well. So you should end up with something like:

        If IsNull(Key1) Then
        Key1 = KeyList
        Elseif IsNull(Key2) Then
        Key2 = KeyList
        Else
        Key3 = KeyList
        End If

Resources