有没有办法在访问表单上有条件地列出字段名称? [英] Is there a way to conditionally list field names on an access form?

查看:64
本文介绍了有没有办法在访问表单上有条件地列出字段名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大型数据库,可以监视员工参加培训活动的情况.每条记录都是一名雇员,并且(连同基本信息)有一百多个字段代表过去十年的培训活动.这些字段均为是/否"复选框,因此将检查员工是否参加了该研讨会.

I have a large database that monitors employees attendance at training events. Each record is an employee, and there are (along with basic information) a hundred or so fields that represent training events over the last 10 years. These fields are all yes/no checkboxes and so are checked if the employee attended that workshop.

我有一个表格,可以轻松查看各个员工的信息,但是我想在此表格上创建一个动态列表,以显示当前所选员工参加的活动.

I have a form that allows viewing information for individual employees easily, but I want a dynamic list on this form that shows what events the currently selected employee attended.

所以我想要一个列表来查看指定记录的哪些字段被指定为true.

So I want a list to see which fields are designated as true for the specified record.

有没有办法做到这一点?整天都在搜索,找不到解决方案.谢谢.

Is there any way to do this? Been searching all day and can't find a solution. Thanks.

推荐答案

也许是这样的,假设所有boolean字段都是相关的,并且字段名称是工作坊名称:

Maybe somthing like this, assuming that all boolean fields are relevant and field name is workshop name:

Public Function getWorkshops(ByVal strEmployee As String) as String
' Declare vars
Dim db as DAO.Database
Dim rs as DAO.Recordset
Dim lngFieldsCount as Long
Dim n as Long
Dim strWorkshops as string

Set db = CurrentDb() '
lngFieldsCount = db.TableDefs("myTable").Fields.Count ' Count number of fields to iterate through
Set rs = db.OpenRecordset("SELECT * FROM myTable WHERE employeeName LIKE '" & strEmployee & "';",DbOpenSnapshot)
Do While not rs.Eof
  For n = 0 to lngFieldsCount -1 ' iterate through all fields
    If TypeOf rs.Fields(n) is dbBoolean Then ' check if field is boolean
      If rs.Fields(n) Then ' check if boolean is true
        strWorkshops = strWorkshops & rs.Fields(n).Name & vbCrLf ' add field names to string, separated by linebreaks
      End If
    End If
  Next n
  rs.MoveNext
Loop
getWorkshops = strWorkshops 'Set result of function
'Clean up
rs.Close
Set rs = Nothing
Set db = Nothing
End Function

这将返回字符串中所有真实字段的名称,并用换行符分隔(未测试).

This returns the name of all true fields in a string, separated with linebreaks (not tested).

这篇关于有没有办法在访问表单上有条件地列出字段名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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