Populate dropdown box with information from other fields

G

Guest

I currently have a Access VBA database projetc. I have a form which uses
information from a current record. There are fields that populate perfectly.
I would like to add a dropdown box that will display the information from the
various fields.

Example:

The form conatins 3 non-visible fields : Writer1, Writer2, Writer3

I would like the drop-down to display Writer1, Writer2, and Writer3 of the
current record.

Is there a way to have it displayed directly from the object's property
window (Row Source) ?
 
J

John Spencer

You could use the Current Event to set the comboboxes value list.

Set the Row Source Type of your combobox:
Row Source Type: Value List

Private Sub Form_Current()
Dim strList as string
strList = Me.Writer1 & ";" & Me.Writer2 & ":" & Me.Writer3
Me.YourCombobox.RowSource = strList
End Sub
--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 
D

Douglas J. Steele

Slight typo. It should be semi-colons in both places:

strList = Me.Writer1 & ";" & Me.Writer2 & ";" & Me.Writer3
 
G

Guest

This code works however it does not show the desired results. Writer1,
Writer2, and Writer3 fields contain comma's in them. For example: Smith, John

The code provided does put the desired information into the drop-down box
but it does not place the full name on the same line.
What happens is: Smith
John
Doe
Jane

I would like it to show as : John, Smith
Jane Doe
 
G

Guest

I have changed the typo to semicolons and the issue is still happening. It is
putting the first and last name on two seperate line.
 
D

Douglas J. Steele

Try

strList = """" & Me.Writer1 & """;""" & Me.Writer2 & """;""" & Me.Writer3 &
""""

That's four double quotes in a row at the beginning and end, and three
double quotes on either side of the semi-colons.
 
J

John Spencer

Perhaps I don't understand what you are attempting to do.

If you are trying to get the three parts of ONE Name as choices in a
combobox then you probably need to use a query as the source for the
combobox where you have concatenated (added together) three fields
containing the name parts. You can combine the three fields in the
underlying query.

Field: FirstName & " " & MiddleName & " " & LastName

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top