Results 1 to 2 of 2

Thread: Can anyone see any problems.

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Posts
    88

    Can anyone see any problems.

    Hi guys CAn anyone see any problems with this userform which does a find and replace and puts the replacement in the second textbox.

    I dont really know wether to use keyup,keypress or keydown it works when u press spacebar. I got it working with vb6 and converted it to vba but the text is not copying but not recieving any errors.

    caz

    heres the code:

    VB Code:
    1. Private db As DAO.Database
    2. Private rs As DAO.Recordset
    3.  
    4.  
    5. Private Sub frmContacts_Load()
    6.  
    7. Set db = OpenDatabase("C:\Documents and Settings\Matthew\Desktop\TEST.mdb")
    8. Set rs = db.OpenRecordset("tblTEST", dbOpenDynaset)
    9. 'Points to access database.
    10.  
    11. End Sub
    12.  
    13. Private Sub TextBox1_Change()
    14. 'TextBox where text is entered.
    15. End Sub
    16.  
    17. Private Sub txtSearchText_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
    18. 'When space pressed shoudl find text in database and send result to
    19. 'TextBox1.
    20.  
    21.     Dim Prts() As String
    22.     Dim tmpText As String
    23.    
    24.     If KeyAscii = 32 Or KeyAscii = 46 Then
    25.        
    26.         If txtSearchText.Text <> "" Then
    27.         tmpText = txtSearchText
    28.             Prts = Split(txtSearchText.Text, " ")
    29.             For X = 0 To UBound(Prts)
    30.                 rs.FindFirst "[SearchText] = '" & Prts(X) & "'"
    31.                 If Not rs.NoMatch Then
    32.                     tmpText = Replace(tmpText, Prts(X), rs.Fields("ReplacementText"))
    33.                 End If
    34.             Next
    35.             TextBox1 = tmpText
    36.         End If
    37.     End If
    38. End Sub
    Last edited by caz1805; May 4th, 2006 at 11:43 PM.

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Can anyone see any problems.

    Have you put a break point on it to see where it is not working?

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

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