Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB Databases Basics
Password Reminder
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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

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
    Do While Not rsMovie.EOF
      .AddItem rsMovie.Fields("FirstName").Value
      .ItemData(.NewIndex) = rsMovie.Fields("UserNo").Value
  End With

  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?


Reply With Quote
  #2 (permalink)  
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

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...


Reply With Quote
  #3 (permalink)  
Old May 17th, 2006, 10:22 AM
Authorized User
Join Date: Jan 2006
Location: , , .
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts

Thanks gbianchi

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 11:45 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.