Results 1 to 8 of 8

Thread: How can help to correct this code plz?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2002
    Posts
    137

    Question How can help to correct this code plz?

    Hi Guys


    I use the code below to search for employee , by using the employee number.

    In the form I have only listview1 and text1 box for search.
    Databse: dbemp
    Recordset:rsemp


    When I use this code I always get this message
    Invalid property value , err 380

    Any one can help please ?
    Thank you in advance

    Private Sub Text1_KeyPress(KeyAscii As Integer)
    Dim x As ListItem
    Set x = ListView1.FindItem("emp_number", lvAccounts, elvSearchText)
    If (x Is Nothing) = False Then
    Set lvAccounts.SelectedItem = x.Selected
    End IfEnd Sub

  2. #2
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Well ...

    Try changing the following line:

    VB Code:
    1. 'Change this line ...
    2. Set lvAccounts.SelectedItem = x
    3. 'To this line ...

    x.Selected is a boolean (Yes/No) property, while the lvAccounts.SelectedItem is an object property (i.e. it holds a ListItem object).

    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2002
    Posts
    137

    Re: Well ...

    Hi honeybee
    Thank you

    I tried this Set lvAccounts.SelectedItem = x
    Instead of Set lvAccounts.SelectedItem = x.Selected but, does not work

    Can you post anther idea please ?

    Thank you so much






    QUOTE]Originally posted by honeybee
    Try changing the following line:

    VB Code:
    1. 'Change this line ...
    2. Set lvAccounts.SelectedItem = x
    3. 'To this line ...

    x.Selected is a boolean (Yes/No) property, while the lvAccounts.SelectedItem is an object property (i.e. it holds a ListItem object).

    .
    [/QUOTE]

  4. #4
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Well ...

    Oh boy! You said you are using only one Listview and one textbox. But you are using the name of the listview control as ListView1 at one place and lvAccounts at the other. Verify your code and use the same listview name at both the places.

    Did you copy the FindItem line from somewhere?

    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Sep 2002
    Posts
    137

    Re: Well ...

    NO, Sir
    I did not copy any , I am using the same code which has only one listview with one textbox, and I need to search by suing the emp_number in the textbox, so can you help again to correct the code if you do not mind please ?

    Thank you



    Originally posted by honeybee
    Oh boy! You said you are using only one Listview and one textbox. But you are using the name of the listview control as ListView1 at one place and lvAccounts at the other. Verify your code and use the same listview name at both the places.

    Did you copy the FindItem line from somewhere?

    .

  6. #6
    Addicted Member Sully's Avatar
    Join Date
    Nov 2002
    Location
    Lost in the far recesses of one's own mind.
    Posts
    165
    You did not fully answer Honeybee's question...also in your FindItem method, you have quoted your search variable, ie "emp_number", which makes it a constant...
    Disclaimer:

    * The preceding message was in no means meant to be critical, mean spirited, insincere, or facetious.

    Disclaimer for disclaimer:

    The preceding disclaimer may in fact be facetious in nature.

    Thanks,
    Jim

  7. #7
    Fanatic Member
    Join Date
    Sep 2000
    Location
    Over There
    Posts
    522
    Here's some code for searching a Listview.
    I would recommend doing the searching in the change event.
    The following code should work

    VB Code:
    1. Private Sub text1_Change()
    2. Dim Item As ListItem
    3.  
    4. Set Item = listview1.FindItem(text1, , , lvwPartial)
    5. If Item Is Nothing Then
    6.    Exit Sub
    7. Else
    8.   Item.EnsureVisible
    9.   Item.Selected = True
    10. End If
    11.  
    12. End Sub
    It Never Fails. Everytime I try to make a program idiot proof, the world makes a better idiot.

  8. #8
    Lively Member
    Join Date
    Nov 2002
    Location
    Michigan
    Posts
    107
    1. As noted above, you have two different names for your listview

    2. Again as noted above, you use "emp_number", which may be in your recordset somewhere, but may not be the key to the listview item. Nowhere in that procedure do you set "emp_number". Once you use the recordset to populate the listview, you don't care about it as far as searching the listview is concerned.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width