Solved

List box

Posted on 2014-02-16
22
358 Views
Last Modified: 2014-02-19
Dim i As Long
        Dim Intnum
        Intnum = Me!txtCustNum
        With Me!lstLoan
            For i = 0 To .ListCount - 1
                If .Column(1, i) Like Intnum Then
                    .Selected(i) = True
                    Exit For
                End If
            Next i
        End With
        SendKeys "{Enter}"
        Me!lstLoan.SetFocus

I have the above code  to find a customer number in a list box then that number is highlighted. It works  fine. I have a button that opens a form to show customer details. At the moment for this to happen I need to click the highlighted row. I used the SendKeys  "{Enter}" function hoping then to just click the command button but I get an error if I don't click on the highlighted row. This is confusing the users. Any help appreciated

chestera
0
Comment
Question by:chestera
  • 14
  • 4
  • 3
  • +1
22 Comments
 
LVL 30

Assisted Solution

by:hnasr
hnasr earned 250 total points
ID: 39863930
Try to add the call to button click event after finding the relevant record
                If .Column(1, i) Like Intnum Then
                    .Selected(i) = True
                    Exit For
                    ' enter code here to run the button click event code
                    theButton_Click
                End If
0
 

Author Comment

by:chestera
ID: 39863977
hnasr

Thank you I will give that a try and get back to you

Alan
0
 

Author Comment

by:chestera
ID: 39863983
hnasr

That won't work because there are four different buttons The user can select depending what they wont to view, for example check payments, check customer details, Add payments etc.
Worth a try if only one button

Alan
0
 
LVL 30

Expert Comment

by:hnasr
ID: 39864189
One way,
Save the selected record info in a hidden text control.

Refer to that control in each button click.
 If .Column(1, i) Like Intnum Then
                    .Selected(i) = True
                    Exit For
                    ' enter code here to save selected item info
                    hiddenTextBox = .Column(1,i)
                End If
0
 

Author Comment

by:chestera
ID: 39864454
hnasr

Thank you will give it a try. Could be a bit of a delay leaving PC for a while

Alan
0
 
LVL 34

Expert Comment

by:PatHartman
ID: 39864865
I don't understand why YOU are selecting something in a list box.  Why not just use the value in Me!txtCustNum?
0
 

Author Comment

by:chestera
ID: 39866199
pathartman


The user selects a customer from the list of customers then selects  one of three cmdButtons depending what they want to view. It's a long list so the user can enter a customer number ans do a search for that customer on the list, the customer is then highlighted. The list also contains useful information for the user to view without using the cmdButtons.

Alan
0
 

Author Comment

by:chestera
ID: 39866375
hnasr

Sorry for the delay had some PC problems oh the delights of Microsoft.
Tried
hiddenTextBox = .Column(1,i)

Didn't work

Bottom line there might not be a solution. I have contacted the users and they are quite happy to just click on customer after using the search.

Alan
0
 
LVL 30

Expert Comment

by:hnasr
ID: 39866492
"Tried
hiddenTextBox = .Column(1,i)

Didn't work"

try to amend:
hiddenTextBox = theValueIdentifiesTheCustomer
0
 

Author Comment

by:chestera
ID: 39867170
hnasr

hiddenTextBox = theValueIdentifiesTheCustomer
Didn't work either. Where does the variable get it's information

Alan
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 39867346
@chestera

how are you referring to the selected item from the listbox, when you click the button?

btw, what version of Access are you using?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 30

Expert Comment

by:hnasr
ID: 39868138
Try to reproduce the issue in a sample database.
0
 

Author Comment

by:chestera
ID: 39869159
Ray Obrera

Hi Ray

Currently using Access 2003 for this particular app.
There is not really an issue here. I have a list box that shows Customer details. There is a button to open a Payment form, The user selects the customer from the list box then click the cmdButton to bring up the payment form. because there are a large number of customers I have introduced a text box where the user enters the cust number and on exit it search and high lights that Customer. To bring up the Payment form at this time the user has to still click on the customer highlighted on the list box. What I am trying to achieve is the user enters Cust # that Customer is highlighted then just click the cmdButton to bring up the payment form.

Dim i As Long
        Dim Intnum
        Intnum = Me!txtCustNum
        With Me!lstLoan
            For i = 0 To .ListCount - 1
                If .Column(1, i) Like Intnum Then
                    .Selected(i) = True
                    Exit For
                End If
            Next i
        End With
        SendKeys "{Enter}"     'THought this might activate the List box as if clicking wiht the mouse
        Me!lstLoan.SetFocus

The problem the list box is not activated. I tried this by using the SendKeys function
Enter
UP, Down etc
AS I have said it isn't a real problem just curious to see if there is away to acheive this

Alan
0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 250 total points
ID: 39869179
where are you calling the codes that you posted?


Dim i As Long
        Dim Intnum
        Intnum = Me!txtCustNum
        With Me!lstLoan
            For i = 0 To .ListCount - 1
                If .Column(1, i) Like Intnum Then
                    .Selected(i) = True

'add this line for testing
                   msgbox "selected item is " &  .itemdata(i)

                    Exit For
                End If
            Next i
        End With

' use the .itemdata(i)   as the value of the selected item from the listbox
0
 

Author Comment

by:chestera
ID: 39869375
Rey Obrero

in the on exit event of the text box the user enters the Customer number

Will try the msg box test
0
 

Author Comment

by:chestera
ID: 39869411
Rey Obrero

Better clear things up the first two colums in the list box are Loan # and Customer #. Col(0) is Loan # and col(1) is Customer #. When The user clicks on a customer from the list box a text box (txtLoan) enabled not visible is populated with a Loan # that is used for  opening a Payment form to the correct loan.  If the user decides to search for a customer by entering a Customer # the txLoan is not populated until the user Clicks on that customer. I was trying to search for a customer and when highlighted the txLoan would be auto populated with the Customer Loan # eliminating the need to click on the list box. This might not be possible.

Alan
0
 

Author Comment

by:chestera
ID: 39869413
Rey Obrero

Forgot to mention when adding   msgbox "selected item is " &  .itemdata(i)
I get the loan #
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 39869442
<When The user clicks on a customer from the list box a text box >
what is the list box event that use to populate the textbox "txtLoan" ?
afterUpdate, onClick ?

post the event and codes here?


also try


Dim i As Long
        Dim Intnum
        Intnum = Me!txtCustNum
        With Me!lstLoan
            For i = 0 To .ListCount - 1
                If .Column(1, i) Like Intnum Then
                    .Selected(i) = True
'try any of this
                      lstLoan_Click  
                     'or
                      lstLoan_afterUpdate

                    Exit For
                End If
            Next i
        End With
0
 

Author Comment

by:chestera
ID: 39869495
Rey Obrero

On the click event of the Listbox

I have
me!txtLoan = me!lstCustomer.Column(0).

I will try the lstloan_click and lstLoan_afterUpdate

Will be a delay for my reply going out to a Birthday party
0
 

Author Comment

by:chestera
ID: 39869535
Rey Obrero

With your help you gave me an idea.

 by doing this

 With Me!lstLoan
            For i = 0 To .ListCount - 1
                If .Column(1, i) Like Intnum Then
                    .Selected(i) = True
                    Me!txtLoanNumber = .ItemData(i)     '-----Added this line
                    Exit For
                   
                End If
            Next i
  End With

It works :)

Alan
0
 

Author Comment

by:chestera
ID: 39869536
Rey Obrero

I used a text box so I could see what was going on. I will replace txtLoan with a variable now it's working
0
 

Author Closing Comment

by:chestera
ID: 39871359
Thank you both your input gave me the idea how to resolve this problem
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now