Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2011
    Posts
    2

    Red face Unanswered: Combining two different words in VBA

    hi! I have a table with field names StudentsID, FirstName, MiddleName, LastName,Course,Address

    I created a form with combo box that when you choose any of the StudentsID, it will automatically populates the other textboxes (such as Name,Course,Address). My problem is, I need to combine the 3 fields in one which is FirstName, MiddleName and LastName into Name(only). I tried this code:

    Dim strFirstName As String
    Dim strMiddleName As String
    Dim strLastName As String
    Dim strName As String

    strName = "Hello" & strFirstName & " " & strMiddleName & " " & strLastName

    but it gives me error, can anyone help me please?

    Thanks in advance

  2. #2
    Join Date
    Jun 2011
    Location
    Inside your mind
    Posts
    297
    What's the error?

    Number, Description and line that's causing it please...

    How are you populating those variables?


    Also: You'd want - strName = "Hello " & strFirstName & " " & strMiddleName & " " & strLastName

    Otherwise it'd display as HelloJohn M Taylor
    Looking for the perfect beer...

  3. #3
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Code:
    Dim strFirstName As String 
    Dim strMiddleName As String 
    Dim strLastName As String 
    Dim strName As String
    
    strName = "Hello" & strFirstName & " " & strMiddleName & " " & strLastName
    As kez1304 has alluded to, you Dim the Variables strFirstName, strMiddleName and strLastName, but don't populate them before doing your Concatenation.

    I think Access is trying to Concatenate the Variables themselves, rather than the Values assigned to them, and is choking.

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •