Results 1 to 10 of 10
  1. #1
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480

    Trim!

    Okay, I have a textbox on a form. It holds a first name, and a last name... separated by a space..



    What I am trying to do, And have zero idea how.. except I can use trim...

    The code below is putting in first and last name in both of the fields.. I have searched the trim function.. and I guess a Ltrim and Rtrim will be used... but not sure how to accomplish this... Any assistance is appreciated.



    Code:
    Sub Adduser()
      Dim oIE As InternetExplorer
      Dim First, Last As String
      Set oIE = FindIE("https://sensitivewebsitedata!!!/")
      
     On Error GoTo NotOpen:
    
    
      oIE.Document.all.tags("a").Item(24).Click
      PauseApp 1.5
      oIE.Document.all.Item("inputFirstName").Value = Forms!frmmainnew!.txtaddUser1  '''This should only be putting in the first name
      oIE.Document.all.Item("inputLastName").Value = Forms!frmmainnew!.txtaddUser1  '''This should only be putting in the Last name
    NotOpen:
    If Err.Number = 91 Then
      MsgBox "L&M Admin is NOT open!"
      MsgBox Err.Number & Err.Source & Err.Description
      End If
        
    Set oIE = Nothing
    End Sub

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,892
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480
    I know this might be a bit much, but Can I see it in a code example? For some reason I keep getting syntax errors. I am trying to follow the examples posted on that website, but a no go.

  4. #4
    live2ride is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jun 2012
    Posts
    70
    dim str,lName,Fname as string
    dim com as integer

    set str = forms!frmmainnew!.txtaddUser1
    com = instr(1,str,",")
    lName = mid(str,1,com)
    fName = mid(str,com + 2 ,50)

  5. #5
    live2ride is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jun 2012
    Posts
    70
    instr is to find location of first string in which case you are looking for comma(,)
    mid is a trim function you specify what youre trimming, start and end
    so you are trimming "str" start is 1 which is the beginning point and your length is your comma

    so str = "Blah, Adam"
    com = 5
    lname = mid("blah, Adam", 1, 5) = "blah,)
    fname = mid(blah, adam",5 + 2,50) = "adam " i used 50 for simplicity if you want to get exact name in case you str = "blah, adam blah"
    you would use another instr function to find end point in which case you subtract end with start
    where start being comma and end being idk space so you are getting everything between space and comme ", Adam" but youre adding + 2 to comma so its "Adam"

  6. #6
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480
    Hmm.. Well my names are actually listed like this "Bob Villa" without the , .. When I tried your code.. the Fname went in as ob Villa and Lname was blank.

  7. #7
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480
    GOT IT! thank you

    Dim str, LName, Fname As String
    Dim com As Integer

    Set str = Forms!frmmainnew!.txtaddUser1

    com = InStr(1, str, " ")
    Fname = Mid(str, 1, com)
    LName = Mid(str, com + 1, 50)

  8. #8
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    You have been given some bad info in the sample.
    I'm sure was well-intended, but
    Dim str, LName, Fname As String is not doing what live2ride thinks.

    In vba you must explicitly declare (Dim) your variables. If you do not, the variables will be of type Variant by default.

    Dim str as String, Lname as String
    Dim Fname as String


    causes these variables to be of Type String.

    see post 13 at
    https://www.accessforums.net/access/...-do-24457.html
    Last edited by orange; 11-07-2012 at 08:11 AM. Reason: spelling

  9. #9
    live2ride is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jun 2012
    Posts
    70
    orange, thanks for the link. i had no idea that was happening although i did encounter few issues in the past few days with my dims where i actually had to separate dim a,b,c,d as string to dim a as string, dim b as string and so on to fix an issue.
    i must have seen this somewhere in the post and started using it since it made sense i guess and it leaves the code little more compact but i see what you are saying and i want to say thanks

  10. #10
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    You are welcome. I was told that many years ago by a poster-- just passing it on.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. How to Trim Values??
    By taimysho0 in forum Programming
    Replies: 3
    Last Post: 06-08-2012, 02:13 PM
  2. Trim vba
    By shexe in forum Access
    Replies: 5
    Last Post: 11-16-2011, 10:20 AM
  3. Trim value
    By dada in forum Programming
    Replies: 5
    Last Post: 09-02-2010, 11:01 PM
  4. Need Help with TRIM command
    By rbfarley in forum Reports
    Replies: 3
    Last Post: 01-08-2010, 02:03 PM
  5. Trim
    By JMantei in forum Forms
    Replies: 1
    Last Post: 06-20-2006, 02:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums