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:
Private db As DAO.Database Private rs As DAO.Recordset Private Sub frmContacts_Load() Set db = OpenDatabase("C:\Documents and Settings\Matthew\Desktop\TEST.mdb") Set rs = db.OpenRecordset("tblTEST", dbOpenDynaset) 'Points to access database. End Sub Private Sub TextBox1_Change() 'TextBox where text is entered. End Sub Private Sub txtSearchText_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) 'When space pressed shoudl find text in database and send result to 'TextBox1. Dim Prts() As String Dim tmpText As String If KeyAscii = 32 Or KeyAscii = 46 Then If txtSearchText.Text <> "" Then tmpText = txtSearchText Prts = Split(txtSearchText.Text, " ") For X = 0 To UBound(Prts) rs.FindFirst "[SearchText] = '" & Prts(X) & "'" If Not rs.NoMatch Then tmpText = Replace(tmpText, Prts(X), rs.Fields("ReplacementText")) End If Next TextBox1 = tmpText End If End If End Sub




Reply With Quote