Two words in a text box

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am having a textbox that saves its value in a field on a table.
I am wondering if there is a way that i can detect the entry of two words so
i can save them into two separate fields based on the first and second word

CurrentDb.Execute "UPDATE Values SET [ID] = '" & (first word from Me.Input)
& "' WHERE [Key] = " & Me.Record
CurrentDb.Execute "UPDATE Values SET [Name] = '" & (second word from
Me.Input) & "' WHERE [Key] = " & Me.Record

is it possible??
 
Use the InStr function to look for a space within the text, and the Left$
and Mid$ functions to parse it. Here are some examples using the Immediate
Window for illustration purposes ...

? InStr(1, "Some Text", " ")
5
? Left$("Some Text", InStr(1, "Some Text", " ") -1)
Some
? Mid$("Some Text", InStr(1, "Some Text", " ") + 1)
Text

See the help topics for the above functions for more information.
 
Dim varSplit As Variant
Dim strSQL As String

varSplit = Split(Me.Input, " ")
strSQL = "UPDATE Values SET [ID] = '" & varSplit(0) & "'"
If UBound(varSplit) > 0 Then
strSQL = strSQL & " , [Name] = '" & varSplit(1) & "'"
End If
strSQL = strSQL & WHERE [Key] = " & Me.Record & ";"
CurrentDb.Execute strSQL, dbFailOnError
 
I am having a textbox that saves its value in a field on a table.
I am wondering if there is a way that i can detect the entry of two words so
i can save them into two separate fields based on the first and second word

If you're really doing this with people's names, don't forget that
some single names consist of two or more words. I have known people
with first names "Bobbie Lou" and "Rhoda Mae" - and that is the name
they use in day to day conversation; and last names like "van der
Steen" or "de la Cruz" are not uncommon.

John W. Vinson[MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top