F
Frank
Hi
I have a 2-column combo box "cboCourseID", it has two columns: "course
id"
and "Course title". The bound column is "course id" and it is hidden
(its width is set to 0). So the user will see only the course title.
I was unable to set the default value to this combo box. The code
section is shown below. When I run the code it stops at the line
"Me.cboCourseID.Value = Me.cboCourseID.ItemData(0)"
and showed the error message "You can't assign a value to this object".
The sql works fine. It returns all courses run by a department, and
accDept is
the department code. If the line
"Me.cboCourseID.Value = Me.cboCourseID.ItemData(0)"
is commented out., the section of code works fine except that the
default value was shown as the value left by previous run (which I do
not want).
The similar code works for 1 column combo box. I would be very grateful
if someone can help me to show me where is wrong. Thanks.
Private Sub Form_Open(Cancel As Integer)
Dim sql As String
'Loading a list of courses offered by dept
Me.cboCourseID.RowSourceType = "Table/Query"
sql = "SELECT [Course Dept Table].[course id], [Course Info
Table].Title "
sql = sql & "FROM [Course Dept Table] INNER JOIN [Course Info
Table] ON "
sql = sql & "[Course Dept Table].[course id] = [Course Info
Table].[course id] "
sql = sql & "WHERE ((([Course Dept Table].Dept) = "
sql = sql & "'" & accDept & "')) ORDER BY [Course Dept
Table].[course id];"
Me.cboCourseID.RowSource = sql
Me.cboCourseID.Value = Me.cboCourseID.ItemData(0)
End Sub
I have a 2-column combo box "cboCourseID", it has two columns: "course
id"
and "Course title". The bound column is "course id" and it is hidden
(its width is set to 0). So the user will see only the course title.
I was unable to set the default value to this combo box. The code
section is shown below. When I run the code it stops at the line
"Me.cboCourseID.Value = Me.cboCourseID.ItemData(0)"
and showed the error message "You can't assign a value to this object".
The sql works fine. It returns all courses run by a department, and
accDept is
the department code. If the line
"Me.cboCourseID.Value = Me.cboCourseID.ItemData(0)"
is commented out., the section of code works fine except that the
default value was shown as the value left by previous run (which I do
not want).
The similar code works for 1 column combo box. I would be very grateful
if someone can help me to show me where is wrong. Thanks.
Private Sub Form_Open(Cancel As Integer)
Dim sql As String
'Loading a list of courses offered by dept
Me.cboCourseID.RowSourceType = "Table/Query"
sql = "SELECT [Course Dept Table].[course id], [Course Info
Table].Title "
sql = sql & "FROM [Course Dept Table] INNER JOIN [Course Info
Table] ON "
sql = sql & "[Course Dept Table].[course id] = [Course Info
Table].[course id] "
sql = sql & "WHERE ((([Course Dept Table].Dept) = "
sql = sql & "'" & accDept & "')) ORDER BY [Course Dept
Table].[course id];"
Me.cboCourseID.RowSource = sql
Me.cboCourseID.Value = Me.cboCourseID.ItemData(0)
End Sub