Refering to a Listbox

Chrisopia

Registered User.
Local time
Yesterday, 22:35
Joined
Jul 18, 2008
Messages
279
In Short: How do I refer to a listbox instead of a textbox on the same form?


In detail:
On the form: "Search"
There is a listbox names: QuickSearch which is linked to "Query1"
Below which there is a bunch of text boxes relating to the same query. the idea is to click on an item in the listbox and it will fill in the text boxes. I come to a problem when the Company Name is missing and I am trying to get it to Search by last name if it is missing...

Code:
Private Sub QuickSearch_AfterUpdate()

  If Len(Me.CompanyName) Then
      SearchByCompanyName (Me.CompanyName)
      MsgBox Len(Me.CompanyName)
    Else
      SearchByLastName (Me![LastName])
      MsgBox Len(Me![LastName])
    End If
End Sub

I've been drumming over this porblem for a while now and it was only now I figured out the porblem, only I can't seem to find a solution.

the problem is, Len(Me.CompanyName) Kept returning the number 14, from the msgBox. I then realised why. Instead of filling the text box with the data of the item I just clicked, it filled it in with the next thing on the list with a company name... which has 14 characters in it.

I realised Len(Me.CompanyName) is reading from the text boxes instead of the list boxes! I need to solve this please :).
 
>>> If Len(Me.CompanyName) Then <<<

As a point of interest, I like the Len in the If Statement, if it returns zero, its false, hence nothing happens, however if its greater than zero it returns true. Haven't seen this done before, excellent!
 
:) I can't take credit, I've seen it been used many times before... I just cant seem to refer to the right control to use it properly.
 
i think it is still the same. but instead of using afterupdate, use doubleclick instead.
 
The Len() function will cause an error if the textbox is Null. You'll have to remove the Null condition with this....

Code:
If Len(Me.CompanyName & "") Then

Note: There is no space between the double quotes.

In Short: How do I refer to a listbox instead of a textbox on the same form?


In detail:
On the form: "Search"
There is a listbox names: QuickSearch which is linked to "Query1"
Below which there is a bunch of text boxes relating to the same query. the idea is to click on an item in the listbox and it will fill in the text boxes. I come to a problem when the Company Name is missing and I am trying to get it to Search by last name if it is missing...

Code:
Private Sub QuickSearch_AfterUpdate()

  If Len(Me.CompanyName) Then
      SearchByCompanyName (Me.CompanyName)
      MsgBox Len(Me.CompanyName)
    Else
      SearchByLastName (Me![LastName])
      MsgBox Len(Me![LastName])
    End If
End Sub

I've been drumming over this porblem for a while now and it was only now I figured out the porblem, only I can't seem to find a solution.

the problem is, Len(Me.CompanyName) Kept returning the number 14, from the msgBox. I then realised why. Instead of filling the text box with the data of the item I just clicked, it filled it in with the next thing on the list with a company name... which has 14 characters in it.

I realised Len(Me.CompanyName) is reading from the text boxes instead of the list boxes! I need to solve this please :).
 

Users who are viewing this thread

Back
Top Bottom