How To Set The RowSource property of a combo box via code

  • Thread starter nouveauricheinvestments
  • Start date
N

nouveauricheinvestments

Hi,

I am trying to use the following code to populate a combo box.
Essentially what is happening here is I have a textbox on another form
and I am setting the ID = to the textbox's value's primary key by
looking it up in the table with the dlookup function. When I try to
set the RowSource property however, the only option I have in the
dropdown menu is DAT, rather than the values in the DAT field. DAT
stands for Date And Time by the way - I should see the relevant dates
from the table. What should I do differently?

Private Sub MyTickets_Click()
Dim ID As Integer
ID = DLookup("[ID]", "Trade_Specialists", "[Trade_Specialist] =
[Forms]![frmSplash]![User]")
Me.MyTickets.RowSourceType = "Field List"
Me.MyTickets.RowSource = "SELECT [Pending Tickets].DAT FROM [Pending
Tickets] WHERE " & _
"[Pending Tickets].ResearchedByID = " & ID & ";"
End Sub
 
F

fredg

On Fri, 21 Nov 2008 06:52:39 -0800 (PST),
Hi,

I am trying to use the following code to populate a combo box.
Essentially what is happening here is I have a textbox on another form
and I am setting the ID = to the textbox's value's primary key by
looking it up in the table with the dlookup function. When I try to
set the RowSource property however, the only option I have in the
dropdown menu is DAT, rather than the values in the DAT field. DAT
stands for Date And Time by the way - I should see the relevant dates
from the table. What should I do differently?

Private Sub MyTickets_Click()
Dim ID As Integer
ID = DLookup("[ID]", "Trade_Specialists", "[Trade_Specialist] =
[Forms]![frmSplash]![User]")
Me.MyTickets.RowSourceType = "Field List"
Me.MyTickets.RowSource = "SELECT [Pending Tickets].DAT FROM [Pending
Tickets] WHERE " & _
"[Pending Tickets].ResearchedByID = " & ID & ";"
End Sub


Well, I'm completlety confused.
If the combo box RowSourceType is "Field List" all you need do is
give the Rowsource the name of the table you wish to display the field
names of.

Most likely you meant "Table/Query" as the RowsourceType, in whch case
does this line....

ID = DLookup("[ID]", "Trade_Specialists", "[Trade_Specialist] =
[Forms]![frmSplash]![User]")

return the correct ID value?
If so try:

Private Sub MyTickets_Click()
Dim ID As Integer
ID = DLookup("[ID]", "Trade_Specialists", "[Trade_Specialist] =
[Forms]![frmSplash]![User]")
Me.MyTickets.RowSourceType = "Table/Query"
Me.MyTickets.RowSource = "SELECT [Pending Tickets].DAT FROM [Pending
Tickets] WHERE [Pending Tickets].ResearchedByID = " & ID & ";"
End Sub

Watch out for word wrap on the longer lines
 
N

nouveauricheinvestments

I am trying to use the following code to populate a combo box.
Essentially what is happening here is I have a textbox on another form
and I am setting the ID = to the textbox's value's primary key by
looking it up in the table with the dlookup function. When I try to
set the RowSource property however, the only option I have in the
dropdown menu is DAT, rather than the values in the DAT field. DAT
stands for Date And Time by the way - I should see the relevant dates
from the table. What should I do differently?
Private Sub MyTickets_Click()
Dim ID As Integer
ID = DLookup("[ID]", "Trade_Specialists", "[Trade_Specialist] =
[Forms]![frmSplash]![User]")
Me.MyTickets.RowSourceType = "Field List"
Me.MyTickets.RowSource = "SELECT [Pending Tickets].DAT FROM [Pending
Tickets] WHERE " & _
"[Pending Tickets].ResearchedByID = " & ID & ";"
End Sub

Well, I'm completlety confused.
If the combo box RowSourceType is "Field List" all you need do is
give the Rowsource the name of the table you wish to display the field
names of.

Most likely you meant "Table/Query" as the RowsourceType, in whch case
does this line....

ID = DLookup("[ID]", "Trade_Specialists", "[Trade_Specialist] =
[Forms]![frmSplash]![User]")

return the correct ID value?
If so try:

Private Sub MyTickets_Click()
Dim ID As Integer
ID = DLookup("[ID]", "Trade_Specialists", "[Trade_Specialist] =
[Forms]![frmSplash]![User]")
Me.MyTickets.RowSourceType = "Table/Query"
Me.MyTickets.RowSource = "SELECT [Pending Tickets].DAT FROM [Pending
Tickets] WHERE [Pending Tickets].ResearchedByID = " & ID & ";"
End Sub

Watch out for word wrap on the longer lines

Problem Solved. Thanks Fred.
 

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