Access连续表单上的动态文本框内容 [英] Dynamic text box content on an Access continuous form

查看:227
本文介绍了Access连续表单上的动态文本框内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表(id,Name,Surname,Address等)。所有字段(除id)可以为NULL。我想要一个表单,我可以找到至少有一个NULL字段的所有记录。我已经查询了(查询设计器),然后我把它连接起来。



在窗体的Detail部分,我放了一个textbox ID (链接到查询),所以我可以拥有至少一个字段为NULL的所有ID。到目前为止这么好,它的工作。



我想通知用户ID后,哪些字段是空白的。所以我放了另一个文本框(名为txt),并使控件像If isNull(Me.Name)然后Me.txt.Value =名称字段为空白。它的工作完美,但只有第一个记录。所有其他记录在textbox txt中都有相同的消息。



代码是这样的(当然stringW和lngth被声明)

  If IsNull(Me.Name.Value)Then 
stringW = stringW& 姓名字段
结束如果

.....(同样的姓氏,电话号码等)

  lngth = Len(stringW) -  1 
stringW = Left $(stringW,lngth)
Me.txt.Value = stringW

似乎表单加载(我把代码在加载部分),它使控件一次,然后复制每个记录的txt文本框中的stringW的内容。



我如何解决?我的意思是,我如何以连续的形式有一个文本框,改变其内容通知用户记录的空白字段?

解决方案

这里的问题是,窗体上显示为连续表单的未绑定文本框将始终显示每个记录相同的值。您可能适用于未绑定文本框的任何VBA操作将仅使用当前记录中的数据。



解决方法是在Access中创建保存的查询计算每个记录的状态,然后根据查询的形式,将文本框绑定到计算的[EmptyFields]字段。



就是样本数据在[Table1]

  id名称姓氏地址
- ----- -------- ---------------------
1 Gord Thompson 123 Main St
2荷马742长荣露台
3佛兰德斯

您可以创建一个这样保存的查询

  SELECT 
[id],
[Name],
[Surname],
[Address],
Mid(IIf(IsNull([Name])),Name,)& IIf(IsNull([Surname]),,Surname )& IIf(IsNull([Address]),,Address,),3)AS EmptyFields
FROM Table1

返回

  id名称姓氏地址EmptyFields 
- - ----- -------- --------------------- -------------
1 Gord Thompson 123 Main St
2荷马742长荣露台姓氏
3佛兰德斯名字,地址

,您可以将该查询用作表单的记录来源


I have a table (id, Name, Surname, Address etc.). All the fields (except id) can be NULL. I want to make a form where I can find all the records that have at least a NULL field. I have made a query (with the query designer) and then I "linked" a continuous form to it.

In the Detail part of the form I put a textbox ID (linked to the query) so I can have all the IDs that have at least a field NULL. So far so good, it works.

I would like to inform the user, after the ID, which fields are blank. So I put another textbox (named txt) and making controls like If isNull(Me.Name) then Me.txt.Value ="Name field is blank". It works perfectly but only for the first record. All the other records have the same message in the textbox txt.

The code is like this (of course stringW and lngth are declared)

If IsNull(Me.Name.Value) Then
stringW = stringW & " Name field,"
End If

..... (the same for Surname, Tel number etc)

lngth = Len(stringW) - 1
stringW = Left$(stringW, lngth)
Me.txt.Value = stringW

It seems that the form loads (I put the code in the load section), it makes the controls once and then copies the content of the stringW in the txt textbox for every record.

How could I resolve it? I mean, how can I have a textbox in the continuous form that changes its' contents informing the user for the blank fields of the record?

解决方案

The problem here is that an unbound Text Box on a form that is displayed as Continuous Forms will always display the same value for every record. Any VBA manipulations you might apply to the unbound Text Box will only use the data from the current record.

A workaround for this would be to create a saved query in Access that calculates the status for each record, then base your form on the query and have the Text Box bound to the calculated [EmptyFields] field.

That is, for the sample data in [Table1]

id  Name   Surname   Address              
--  -----  --------  ---------------------
 1  Gord   Thompson  123 Main St          
 2  Homer            742 Evergreen Terrace
 3         Flanders                       

you could create a saved query like this

SELECT 
    [id],
    [Name],
    [Surname],
    [Address],
    Mid(IIf(IsNull([Name]),", Name","") & IIf(IsNull([Surname]),", Surname","") & IIf(IsNull([Address]),", Address",""),3) AS EmptyFields
FROM Table1

which returns

id  Name   Surname   Address                EmptyFields  
--  -----  --------  ---------------------  -------------
 1  Gord   Thompson  123 Main St                         
 2  Homer            742 Evergreen Terrace  Surname      
 3         Flanders                         Name, Address

and you could use that query as the Record Source for your form.

这篇关于Access连续表单上的动态文本框内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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