Douglas,
This is the event procedure that switches the list of from Projects (text
key field) or Internal Work Orders (number key field)
Private Sub frmCost_Object_Type_AfterUpdate()
If Initialize Then
Me.frmCost_Object_Type.SetFocus
txtCost_Object.Value = Empty ' intializing here is a problem if the
record is being edited.
End If
Select Case frmCost_Object_Type.Value
'Note: option one is not visible because charges to cost centers
currenly
are not used.
Case 1
' ' Receiver CCtr currently is not used--no list is associated at
this point.
' txtCost_Object.RowSource = ""
lblCost_Object.Caption = "Select Cost" & vbCrLf & "Center to
charge"
' txtCost_Object.Value = Empty
' txtCost_Object.RowSource = "Select [Old Cost Center], [Stat
Order
#],Description FROM [Hospital - Stat Order #] WHERE Description Like ""R&D
non Project related activities"" ORDER BY [Old Cost Center] ASC;"
txtCost_Object.RowSource = "SELECT [Hospital - Stat Order #].[Old
Cost Center], [Hospital - Stat Order #].[Stat Order #], [Hospital - Stat
Order #].Description " _
& "FROM [Hospital - Stat Order #] " _
& "WHERE ((([Hospital - Stat Order
#].Description) Like ""*non Project related activities*"")) " _
& "ORDER BY [Hospital - Stat Order
#].[Old Cost Center];"
txtCost_Object.ColumnWidths = "0.8 in;0 in; 3 in"
txtCost_Object.BoundColumn = 1 ' null
txtCost_Object.LimitToList = True
txtCost_Object.ListRows = 5
txtCost_Object.ColumnCount = 1
txtCost_Object.ListWidth = 3.8 * 1440 'convert to inches.
Case 2
lblCost_Object.Caption = "Select Stat" & vbCrLf & "Order Number"
' txtCost_Object.Value = Empty ' intializing here is a problem if
the record is being edited.
txtCost_Object.RowSource = "SELECT [Hospital - Stat Order #].[Stat
Order #], [Hospital - Stat Order #].[Projects / Territories] FROM
[Hospital -
Stat Order #];"
txtCost_Object.ColumnWidths = "0.8 in;3 in"
txtCost_Object.BoundColumn = 1
txtCost_Object.LimitToList = True
txtCost_Object.ListRows = 8
txtCost_Object.ColumnCount = 2
txtCost_Object.ListWidth = 4.3 * 1440 'convert to inches.
Case 3
lblCost_Object.Caption = "Select" & vbCrLf & "Project"
' txtCost_Object.Value = Empty
txtCost_Object.RowSource = "WBS - R&D Costs Project List"
txtCost_Object.ColumnWidths = "1.1 in;3 in"
txtCost_Object.BoundColumn = 1
txtCost_Object.LimitToList = True ' allow free input, until OnExit
event.
txtCost_Object.ListRows = 8
txtCost_Object.ColumnCount = 2
txtCost_Object.ListWidth = 4.1 * 1440 'convert to inches.
Case Else
End Select
' Me.txtCost_Object = ""
End Sub
When I am testing the combobox selection. The data mismatch error occurs
when I select a Project item on the list. It seems to me that the
combobox
is expecting a numeric value, and I think that the Data Type is being
inherited from the Query's first field which is the value that is saved to
the combobox when a listed item is selected. Note that the types are
diffetent for the Projects and Internal Orders.
Is there a way to ? I would
like to avoid chaning table properties because I am not the original
designer
(controller originally designed this). Any ideas will be greately
appreciated.
Douglas J. Steele said:
AFAIK, items in combo boxes and list boxes are text, regardless of what
they're displaying.
What's the code that's raising your error?
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
Error 2113 on a ComboBox - wrong data type for control
I have a form with an unbound combobox that displays a list of projects
(text key field). Based on one of two option buttons selected, I
switch
the
projects list to a list of internal orders (number key field). The
combobox
works fine when the option is to diaplay internal orders list, and it
gives
data type mismatch error (#2113) when an item for the project list is
selected.
Is there a way to explicitely set the data type for the combobox? I
like
to
set it to text type so that it will take the number or string.