Trim with space two values (1 Viewer)

cluendo

Registered User.
Local time
Yesterday, 19:02
Joined
Jan 22, 2011
Messages
41
Can Someone fix this code please? Highlighted in RED. Basically it just gets the values from the ComboBox.. The thing is, it "gets" the values of First And Last Name correctly only when the Name ANd Last Name are equal lenght for instance: if the name is John Elli, everything is OK. If the Last Name is long the I get like this: Entered in combox box - John Greggor. I get - John Gregg. Missing the end?
Any Ideas?
Code:
Private Sub Form_Load()
If Not IsNull(OpenArgs) Then
        
[COLOR="Red"]DoCmd.GoToRecord acDataForm, "Patients", acNewRec
        Me.LastName = Trim(Left(OpenArgs, Len(OpenArgs) - (InStr(OpenArgs, " "))))
        Me.FirstName = Trim(Right(OpenArgs, Len(OpenArgs) - (InStr(OpenArgs, " "))))[/COLOR]
   
End If


End Sub
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 12:02
Joined
Jan 20, 2009
Messages
12,859
Those are clumsy expressions.

Use:
Me.LastName = Left(OpenArgs, InStr(OpenArgs, " " - 1)
Me.FirstName = Mid(OpenArgs, InStr(OpenArgs, " " + 1)
 

cluendo

Registered User.
Local time
Yesterday, 19:02
Joined
Jan 22, 2011
Messages
41
Hey, thank You for reply!

When I use your code:

Code:
   Me.LastName = Left(OpenArgs, InStr(OpenArgs, " " - 1))
 Me.FirstName = Mid(OpenArgs, InStr(OpenArgs, " " + 1))

I got Runtime error 13
Type Mismatch


Any Ideas?
 

cluendo

Registered User.
Local time
Yesterday, 19:02
Joined
Jan 22, 2011
Messages
41
Ok I managed to fix that:

code now:

Code:
      Me.LastName = Left(OpenArgs, InStr(OpenArgs, " ") - 1)
 Me.FirstName = Right(OpenArgs, InStr(OpenArgs, " ") + 1)

No error message, but Now Last Name representing ok no matter how long it will be. But First Name now ruins ups. Example: I type in combobox - Fixenman Ali. I got: First Name: xenman Ali Last Name: Fixenman
 

cluendo

Registered User.
Local time
Yesterday, 19:02
Joined
Jan 22, 2011
Messages
41
Im Sorry, everything works fine! Thank YOU!!!!

I forgot to change Right to Mid

Code:
  Me.LastName = Left(OpenArgs, InStr(OpenArgs, " ") - 1)
 Me.FirstName = [COLOR="Red"]Mid[/COLOR](OpenArgs, InStr(OpenArgs, " ") + 1)
 
Last edited:

Galaxiom

Super Moderator
Staff member
Local time
Today, 12:02
Joined
Jan 20, 2009
Messages
12,859
Sorry about the misplaced bracket. Glad you sorted it out.
 

Users who are viewing this thread

Top Bottom