Solved

Urgent!!!! Combo Box Dilemma!!!

Posted on 2002-03-24
9
187 Views
Last Modified: 2010-05-02
Hi Guys,

Can I combine two fields, say last name & first name in just one combobox. I am encountering errors trying to do so. Could you please help me with this?

Thanks in advance and Happy Easter
0
Comment
Question by:jay_acbo
9 Comments
 
LVL 50

Expert Comment

by:Ryan Chong
ID: 6893072
What is the error appears? any code avaible? ..
0
 
LVL 1

Expert Comment

by:Neo78
ID: 6893078
Yes u can....here's a suggestion which u have to modify for it to work for u

With cmbData(0)
    .Clear
    If cRcs.boo_ReadData("LeaveType") Then
      While Not cRcs.rcs_ReadData.EOF
        .AddItem cRcs.rcs_ReadData!TypeOfLeave & _
                 "  : " & cRcs.rcs_ReadData!LeaveDesc & ""
        cRcs.Move NextRecord
      Wend
    End If
End With

cRcs.boo_readData is my function call which is a class module. So based on how u declare your recordset and its connections, u can try replacing mine with yours.
But the main part should look like the line : .AddItem....!TypeOfLeave & _.....

In the example, my table is LeaveType, the two fields are TypeOfLeave and LeaveDesc and combobox is cmbData(0).

Regards.
0
 
LVL 5

Accepted Solution

by:
raizon earned 40 total points
ID: 6893098
the way I do this in SQL is build my SQL statment like so.

sql = "SELECT lname + fname As fullName from Table"
rs.Open sql, conn

If not rs.EOF then
  while not rs.EOF
    cmbData.AddItem rs("fullName")
  wend
End If

but basically the concept is combining the two fields from your database in your sql statment and aliasing them as a single field.
0
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
LVL 1

Expert Comment

by:CodeWizrd
ID: 6893122

The previous answers are all good, except I would trim the fields when putting them together like so:

cboDropdown.additem trim(firstname) & " " & trim(lastname)

This way, your drop down would contain "Rich Smith" instead of potentially "Rich            Smith           " depending on how your database is set up.

0
 

Author Comment

by:jay_acbo
ID: 6893466
actually, i'm using a data combo control....
0
 
LVL 50

Expert Comment

by:Ryan Chong
ID: 6893492
Then what's the problem? ..
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 6893670
then use raizon idea: sql = "SELECT lname + fname As fullName from Table"
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7637808
Hi jay_acbo,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept raizon's comment(s) as an answer.

jay_acbo, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 

Expert Comment

by:SpideyMod
ID: 7753630
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question