根据表单的组合框选择(使用VBA)在子表单上显示记录 [英] Display a record on subform based on form's combo box selection (using VBA)

查看:166
本文介绍了根据表单的组合框选择(使用VBA)在子表单上显示记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个主窗体,其中有一个组合框,我已将其命名为 FLRecCombo .最初是这样设置的,以便在组合框中选择一个选项将移动到主窗体的记录源上的该记录.

I have a main form, which has a combo box i've named FLRecCombo. This was originally set up so that selecting an option in the combo box would move to that record on the main form's record source.

然后我在主表单上也有子表单,当初次设置时,它会根据当前使用通用字段的主表单所基于的任何记录源,将其移至其记录源中的记录(即,可以使用组合框)移至所有子表单上的给定记录).

I then also had subforms on the main form, which when initially set up would move to their record in their record source based on whatever record source the main form was currently on using a common field (i.e. you could use the combo box to move to a given record on all subforms).

请注意,所有这些都是过去时...

Note how all this is in the past tense...

我想在VBA中的 FLRecCombo AfterUpdate事件中添加一些代码;不幸的是,这似乎已经切断了组合框,主窗体和子窗体之间的关系.我认为可能在 FLRecCombo AfterUpdate事件中创建了一个宏,我已经通过遍历代码生成器来轻率地忽略了该宏.

I wanted to add some code to the FLRecCombo AfterUpdate event in VBA; unfortunately this seems to have cut the relationships between combo box, main form and subforms. I think possibly there was a macro created in the FLRecCombo AfterUpdate event, which I've brashly overwitten by going through the code builder.

如何恢复最初的行为?我已经尝试过在此网站上建议的一种方法.这是对象引用:

How might I reinstate the behaviour I initially had? I've tried a method that was suggested on this website; here's the object references:

  • 子表单名称: Finance_FunderAllocation子表单
  • 子窗体记录源: Finance_HeadRec_FunderAllocation
  • 要匹配的子记录记录源字段名称:筹款行
  • 要匹配的表单记录源字段名称: FundingLine
  • Subform name: Finance_FunderAllocation subform
  • Subform record source: Finance_HeadRec_FunderAllocation
  • Subform record source field name to match: Funding Line
  • Form record source field name to match: FundingLine

这是我尝试过的代码:

Private Sub FLRecCombo_AfterUpdate() 

    With Me.[Finance_FunderAllocation subform].Form.Recordset
        .FindFirst "Funding Line=" & Me.FLRecCombo
    End With 

End Sub

访问调试器虽然不喜欢这样,但是说:

Access debugger doesn't like this though, saying:

运行时错误"3077":

Run-time error '3077':

表达式中的语法错误(缺少运算符).

Syntax error (missing operator) in expression.

然后突出显示以 .FindFirst

任何帮助将不胜感激!

推荐答案

应显示为:

 .FindFirst "[Funding Line]=" & Me.FLRecCombo

或者,如果资助行是文本,则可能是这样:

Or possibly, if funding line is text:

 .FindFirst "[Funding Line]='" & Me.FLRecCombo & "'"

您需要方括号,因为您的字段名称中有一个空格.出于您自己的考虑,请考虑删除表和字段名称中的所有空格.

You need the square brackets because you have a space in your field name. For your own sake, consider getting rid of all spaces in table and field names.

最后,您可以对子窗体的链接子字段和主字段进行大量操作,包括无需任何代码即可过滤子窗体的内容.

Finally, you can do an awful lot with link child and master fields for subforms, including filtering the contents of the subform without any code.

 Link Master Fields: MyCombo
 Link Child Fields : [Funding Line]

这篇关于根据表单的组合框选择(使用VBA)在子表单上显示记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆