Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MS Access: use VBA to split a string from a text box into other text boxes

I want to split a string in a textbox into many text boxes each box containing one word using vba in Access

so lets say the text box name text1 and it contains a string like hello I'm asking a question

I want to split that string into text boxes so it would be like

text2 = hello
text3 = I'm
text4 = asking
 ...etc 

is there an easy way to do it?

like image 415
A Kasem Avatar asked Oct 29 '25 20:10

A Kasem


1 Answers

Access has a built in split() command that will do this.

So, this code will work:

Dim v        As Variant
Dim sOne     As Variant
Dim i        As Integer

v = Split(Me.TextBox0, " ")
i = 0
For Each sOne In v
   i = i + 1
   Me("text" & i) = sOne
Next

So above would take the string from a textbox0 on a form, and put say 3 values into textbox 1 to 3.

So a large whack of code is not required.

like image 140
Albert D. Kallal Avatar answered Nov 01 '25 13:11

Albert D. Kallal