Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB Databases Basics
| Search | Today's Posts | Mark Forums Read
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 17th, 2006, 07:09 AM
Authorized User
 
Join Date: Jan 2006
Location: , , .
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default Display 2 fields as one line in the combobox

Hi guys,

I have a comboBox which is populated by records from the database. The code that I use to do this is

Code:
Set cnAddMovie = New ADODB.Connection
cnAddMovie.Provider = "Microsoft.Jet.OLEDB.4.0"
cnAddMovie.Open App.Path & "./tek.mdb"

Set rsMovie = New ADODB.Recordset
'Add another ComboBox
Dim strSQL As String    
 
   strSQL = "SELECT UserNo, FirstName, LastName FROM users"


  rsMovie.Open strSQL, cnAddMovie, adOpenForwardOnly, adLockReadOnly, adCmdText

  With cboNames
    .Clear
    Do While Not rsMovie.EOF
      .AddItem rsMovie.Fields("FirstName").Value
      .ItemData(.NewIndex) = rsMovie.Fields("UserNo").Value
      rsMovie.MoveNext
    Loop
  End With

  rsMovie.Close
  Set rsMovie = Nothing

End Sub
This ends up displaying the first name in the combobox. How can I include the last name field to appear on the same line with FirstName?

Thanks

 
Old May 17th, 2006, 09:18 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hello there...

you have 2 ways to do this...

first one, modify the sql to return one field that has the first and last name the way you want to show it on the combo box

strSQL = "SELECT UserNo, (FirstName+' '+LastName) As Name FROM users"

other way is to do this when you fill the combo box, something like

.AddItem rsMovie.Fields("FirstName").Value & " " & rsMovie.Fields("LastName").Value

either way will do the same...


HTH

Gonzalo
 
Old May 17th, 2006, 10:22 AM
Authorized User
 
Join Date: Jan 2006
Location: , , .
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks gbianchi





Similar Threads
Thread Thread Starter Forum Replies Last Post
display Records in ComboBox therese C# 2005 4 July 26th, 2008 05:28 AM
how to display 2 fields as a choice in 1 combobox dilipv General .NET 0 March 5th, 2008 07:21 AM
concatenationg text fields into one line gregalb SQL Server 2000 2 July 2nd, 2007 11:20 PM
Problem with labels and entry fields on same line ectounix CSS Cascading Style Sheets 3 April 3rd, 2006 12:35 PM
date display memeber in combobox twaghorn C# 2 July 13th, 2003 10:14 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.