完成某些字段后,使字段在MS Access表单中可见 [英] Make fields visible in MS Access form as certain fields are completed

查看:77
本文介绍了完成某些字段后,使字段在MS Access表单中可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在MS Access中构建一个表单,供用户输入数据,但是可能有太多字段.大多数情况下,只会使用一半的字段.

I am building a form In MS Access for users to input data but there are too many possible fields. Most of the time only about half the fields will be used.

因此,我希望某些字段仅根据用户在先前给定字段上输入的内容来显示.

I thus would like to have certain fields appear only depending on what the user inputted on a prior given field.

例如:用户输入项目编号,标题,然后检查是/否"工程.自从他检查之后,这意味着工程受到了影响,因此出现了许多用户必须填写的字段.

Ex: user enters project number, title, then he checks a "yes/no" engineering. since he checked it this means engineering is impacted so a dozen fields that the user will have to fill out appear.

这可能吗?

1)没有VBA

2)使用VBA

推荐答案

如果没有VBA,可能无法实现.

Probably not possible without VBA.

以VBA为例:

  1. 确保您的表单处于设计"视图中
  2. 右键单击组合框,构建事件,代码生成器

这将打开表单后面的代码.它使您进入BeforeUpdate事件的默认代码.我们需要Change事件,因此在右上角将下拉列表从BeforeUpdate更改为Change.这将为您提供如下代码:

This opens the code behind your form. It drops you into the default code for the BeforeUpdate event. We want the Change event instead, so at the top right change the drop down from BeforeUpdate to Change. This will give you a bit of code like this:

Private Sub Field1_Change()

End Sub

在这里,您要检查组合框的值并根据需要隐藏字段:

Inside here, you want to check the value of the combo box and hide fields as required:

假设组合框的名称为Field1(当然,您的名称会有所不同),则添加一些代码,使其看起来像这样来隐藏Field2:

Assuming the name of your combo box is Field1 (yours of course will be different), you add some code so it looks like this to hide Field2:

Private Sub Field1_Change()
  If Field1.Value = "Yes" Then
      Me.Field2.Visible = False
  End If
End Sub

请注意,您需要知道所有字段的名称-这位于属性"框中的其他"选项卡的名称"字段(F4)中.您应该给所有字段起一个合理的名称,以便您了解代码中正在发生的事情.

Note you need to know the names of all your fields - this is in the Other tab, Name field in the properties box (F4). You should give all of your fields sensible names so you can understand what is going on in the code.

对于一个复选框,请遵循完全相同的过程,但是您可能需要使用Click事件.只是实验.

For a check box, follow exactly the same procedure, but you probably need to use the Click event. Just experiment.

示例复选框代码:

Private Sub Check5_Click()
  ' Note: vbTrue = -1
  If Me.Check5 = vbTrue Then
    MsgBox ("Ticked")
  Else
MsgBox ("Not Ticked")
  End If
End Sub

这篇关于完成某些字段后,使字段在MS Access表单中可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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