Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Separate string into word

Status
Not open for further replies.

Kherozen

Programmer
Jun 5, 2003
129
CA
The code that follow could be use in many occasion :

Don't know if there's a better solution but that one works well, so if you want to pass more than one Argument to a form when you open it.

'In the On_Click Event of the button that open the form
Code:
Dim stOpenArgs as string
Dim Delim as String
Delim = " "
stOpenArgs = "
arg1
Code:
" & Delim & "
arg2
Code:
" & Delim & "
arg3
Code:
"
DoCmd.OpenForm "theForm",,,,,,stOpenArgs
now there's some code to separate the arguments in the form you just open

'In the On_Open event of the form you want to open
Code:
Dim stOpenArgs As String
Dim Delim As String
Delim = " "
'Could be anything (be aware that if you use a Letter it could cause so problem.)
Code:
If Not IsNull(Me.OpenArgs) Then
    stOpenArgs = Me.OpenArgs
    Dim Args(40) As String
'change the 40 to what you want
Code:
    Dim cpt As Integer
    cpt = 0
    
    Dim position
    While Len(stOpenArgs)
        position = InStr(stOpenArgs, Delim)
        If position = 0 Then
'No Delim so there's just a word
Code:
            Args(cpt) = stOpenArgs
            stOpenArgs = ""
        Else
            Args(cpt) = Left(stOpenArgs, position - 1)
            stOpenArgs = Right(stOpenArgs, Len(stOpenArgs) - position)
            cpt = cpt + 1
        End If
    Wend
End If
so after that, each arguments are separated.
hope that help
jul ^_^
 
OR to simply split a string:

Dim nameArray As Variant
Dim splitChar as String
Dim yourStringHere as String
Dim Count as Integer

splitChar=";"
youStringHere="1;2;3;4"

nameArray = Split(yourStringHere, splitChar)

For Count = 0 To UBound(nameArray)
'Do something with your string value here
msgbox namearray(count)
Next Count

---
This code can be used to deal with any deliminated string.


 
Damn, I knew something had to exist to split a string ...
heh well Thanks
jul ^_^
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top