首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

在Access中以连续形式自定义组合框的行源

在Access中,可以使用连续形式的自定义组合框来实现行源的自定义组合。以下是一些步骤和建议:

  1. 创建一个新的表单,并将其命名为“自定义组合框表单”。Private Sub AddRow_Click() Dim ctl As Control Dim varItem As Variant Dim intNextID As Integer ' Find the next available ID intNextID = 1 For Each varItem In Me.CustomCombo.Items If IsNumeric(varItem) Then intNextID = intNextID + 1 End If Next varItem ' Create a new row Set ctl = Me.CustomCombo.AddItem(intNextID) ' Set the text box value ctl.Controls("CustomText").Value = "自定义文本" End SubPrivate Sub Save_Click() Dim ctl As Control Dim varItem As Variant Dim intNextID As Integer ' Loop through all the rows in the combo box For Each varItem In Me.CustomCombo.Items Set ctl = Me.CustomCombo.Controls("CustomText" & varItem) ' Save the value to the table DoCmd.RunSQL "INSERT INTO MyTable (ID, Value) VALUES (" & varItem & ", '" & ctl.Value & "')" Next varItem End SubPrivate Sub Load_Click() Dim ctl As Control Dim varItem As Variant Dim intNextID As Integer ' Clear the combo box Me.CustomCombo.Items.Clear ' Loop through all the rows in the table Dim db As DAO.Database Dim rs As DAO.Recordset Set db = CurrentDb Set rs = db.OpenRecordset("SELECT * FROM MyTable") While Not rs.EOF ' Create a new row intNextID = rs!ID Set ctl = Me.CustomCombo.AddItem(intNextID) ' Set the text box value ctl.Controls("CustomText").Value = rs!Value ' Move to the next row rs.MoveNext Wend rs.Close Set rs = Nothing Set db = Nothing End Sub现在,您可以使用“自定义组合框表单”来创建和保存自定义组合框行源,并在需要时加载它们。
  2. 在表单中添加一个新的组合框,并将其命名为“自定义组合框”。
  3. 在组合框中添加一个新的行,并将其命名为“自定义行”。
  4. 在“自定义行”中添加一个新的文本框,并将其命名为“自定义文本框”。
  5. 在“自定义文本框”中输入自定义的文本内容。
  6. 在表单中添加一个新的按钮,并将其命名为“添加行”。
  7. 在“添加行”按钮上添加一个宏,该宏将在单击按钮时运行。
  8. 在宏中添加以下代码,以便在单击“添加行”按钮时将自定义行复制到组合框中:
  9. 在表单中添加一个新的按钮,并将其命名为“保存”。
  10. 在“保存”按钮上添加一个宏,该宏将在单击按钮时运行。
  11. 在宏中添加以下代码,以便在单击“保存”按钮时将组合框中的所有行保存到表中:
  12. 在表单中添加一个新的按钮,并将其命名为“加载”。
  13. 在“加载”按钮上添加一个宏,该宏将在单击按钮时运行。
  14. 在宏中添加以下代码,以便在单击“加载”按钮时将表中的所有行加载到组合框中:
页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

没有搜到相关的沙龙

领券