Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 367
  • Last Modified:

List box

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
chestera
Asked:
chestera
  • 14
  • 4
  • 3
  • +1
2 Solutions
 
hnasrCommented:
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
 
chesteraAuthor Commented:
hnasr

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

Alan
0
 
chesteraAuthor Commented:
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
hnasrCommented:
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
 
chesteraAuthor Commented:
hnasr

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

Alan
0
 
PatHartmanCommented:
I don't understand why YOU are selecting something in a list box.  Why not just use the value in Me!txtCustNum?
0
 
chesteraAuthor Commented:
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
 
chesteraAuthor Commented:
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
 
hnasrCommented:
"Tried
hiddenTextBox = .Column(1,i)

Didn't work"

try to amend:
hiddenTextBox = theValueIdentifiesTheCustomer
0
 
chesteraAuthor Commented:
hnasr

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

Alan
0
 
Rey Obrero (Capricorn1)Commented:
@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
 
hnasrCommented:
Try to reproduce the issue in a sample database.
0
 
chesteraAuthor Commented:
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
 
Rey Obrero (Capricorn1)Commented:
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
 
chesteraAuthor Commented:
Rey Obrero

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

Will try the msg box test
0
 
chesteraAuthor Commented:
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
 
chesteraAuthor Commented:
Rey Obrero

Forgot to mention when adding   msgbox "selected item is " &  .itemdata(i)
I get the loan #
0
 
Rey Obrero (Capricorn1)Commented:
<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
 
chesteraAuthor Commented:
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
 
chesteraAuthor Commented:
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
 
chesteraAuthor Commented:
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
 
chesteraAuthor Commented:
Thank you both your input gave me the idea how to resolve this problem
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 14
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now