I have created a program in visual basic 6 which allows the user to type in text to one textbox and when the spacebar is pressed it checks a Microsoft Access database and places the replacement word in another textbox. This works very well but I would like to emulate this within a VBA Word Userform, I have tried to do this myself but am struggling and i believe this is because the keypress button is not working and I cannot understand why. Or i have not converted it correctly from VB6 to VBA.
Here is the code from the VBA userform which I have made.
Private db As Database
Private rs As Recordset
Private Sub UserForm1_Load()
Set db = OpenDatabase("C:\Documents and Settings\Matthew\Desktop\TEST.mdb")
Set rs = db.OpenRecordset("tblTEST", dbOpenDynaset)
Thanks alot for any help
Private Sub TextBox2_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Dim Prts() As String
Dim tmpText As String
If KeyAscii = 32 Or KeyAscii = 46 Then
If TextBox2.Text <> "" Then
tmpText = TextBox2
Prts = Split(TextBox2.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"))
TextBox1 = tmpText