ComboBox 对象 (Access)(二)
时 间:2022-07-16 08:45:05
作 者:杨雪 ID:42182 城市:南京
摘 要:以下示例演示在加载窗体时如何设置组合框的“RowSource”属性。
正 文:
以下示例演示在加载窗体时如何设置组合框的“RowSource”属性。 当显示该窗体时,存储在“tblDepartment”组合框的“Department”字段中的项目将显示在“cboDept”组合框中。
Private Sub Form_Load() Me.Caption = "Today is " & Format$(Date, "dddd mmm-d-yyyy") Me.RecordSource = "tblDepartments" DoCmd.Maximize txtDept.ControlSource = "Department" cmdClose.Caption = "&Close" cboDept.RowSourceType = "Table/Query" cboDept.RowSource = "Select Department FROM tblDepartments" End Sub
下面的示例演示如何创建在显示另一列时绑定到一列的组合框。 将“ColumnCount”属性设置为 2 可指定“cboDept”组合框将显示由“RowSource”属性指定的数据源的前两列。 将“BoundColumn”属性设置为 1 可指定在检查组合框的值时将会返回存储在第一列中的值。
ColumnWidths 属性指定两列的宽度。 通过将第一列的宽度设置为 0in.,可以在组合框中不显示第一列。
Private Sub cboDept_Enter() With cboDept .RowSource = "Select * FROM tblDepartments orDER BY Department" .ColumnCount = 2 .BoundColumn = 1 .ColumnWidths = "0in.;1in." End With End Sub
以下示例演示如何将项目添加到绑定的组合框。
Private Sub cboMainCategory_NotInList(NewData As String, Response As Integer) On Error GoTo Error_Handler Dim intAnswer As Integer intAnswer = MsgBox("""" & NewData & """ is not an approved category. " & vbcrlf _ & "Do you want to add it now?", vbYesNo + vbQuestion, "Invalid Category") Select Case intAnswer Case vbYes DoCmd.SetWarnings False DoCmd.RunSQL "Insert INTO tlkpCategoryNotInList (Category) " & _ "Select """ & NewData & """;" DoCmd.SetWarnings True Response = acDataErrAdded Case vbNo MsgBox "Please select an item from the list.", _ vbExclamation + vbOKOnly, "Invalid Entry" Response = acDataErrContinue End Select Exit_Procedure: DoCmd.SetWarnings True Exit Sub Error_Handler: MsgBox Err.Number & ", " & Err.Description Resume Exit_Procedure Resume End Sub
Access软件网QQ交流群 (群号:54525238) Access源码网店
常见问答:
技术分类:
源码示例
- 【源码QQ群号19834647...(12.17)
- 按回车键后光标移动到下一条记录...(02.12)
- 【Access Dsum示例】...(02.07)
- Access对子窗体的数据进行...(02.05)
- 【Access高效办公】上月累...(01.09)
- 【Access高效办公】上月累...(01.06)
- Inputbox输入密码打开查...(12.23)
- 【Access Dsum示例】...(12.16)
- Inputbox输入密码打开窗...(12.13)
- 【Access DCount示...(12.02)

学习心得
最新文章
- 用Access查询语句如何得到前3...(02.17)
- Access快速开发平台--导入导...(02.14)
- 按回车键后光标移动到下一条记录的V...(02.12)
- Access快速开发平台--要实现...(02.10)
- Access快速开发平台--让Pe...(02.08)
- 【Access Dsum示例】用D...(02.07)
- Access对子窗体的数据进行平均...(02.05)
- Access快速开发平台附件上传,...(01.18)
- 【IIF函数示例】用iif函数判断...(01.18)
- Access快速开发平台--如何获...(01.17)