子窗体中的未绑定文本框 [英] Unbound Text Boxes in Subform

查看:149
本文介绍了子窗体中的未绑定文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单(Form1),其中包含基本的项目数据和一个子表单,列出了作为连续表单分配给项目的人员。选择该项目上的某个人并单击命令按钮将打开一个新表单(Form2)。


Form2有两个子表单。两者都嵌入在主窗体中。 (Subform2未嵌入在subform1中。)Subform1根据主窗体的主ID将记录显示为连续窗体,并列出分配给某个人的项目。 Subform2未绑定,并根据在Subform1中选择的记录(一个人的项目)将数据显示为常规表单。在Subform1的On Current事件中,我构建了一个SQL语句来过滤支持Subform2的表中的数据。我已经确认SQL语句正确地过滤了数据。


Subform2有许多未绑定的文本框,用于显示与Subform1中选择的项目相关的数据,以及由SQL语句开发的记录集。数据被正确传递给Subform2上的未绑定文本框。


问题是如果Subform1中没有所选项目的数据(记录集为空),则数据来自以前显示的项目仍然显示在未绑定的文本框中,而不是显示为空白的文本框。


这是我用来填充Subform2上未绑定文本框的代码。没有显示完整的SQL字符串以节省空间,但它确实可以正常工作。

I have a form (Form1) which contains basic Project data and a subform listing the personnel assigned to the Project as a continuous form. Selecting a person on that project and clicking on a command button will open a new form (Form2).

Form2 has two subforms. Both are embedded in the main form. (Subform2 is NOT embedded in subform1.) Subform1 displays records as a continuous form based on the Primary ID of the main form and lists the projects a person is assigned to. Subform2 is unbound and displays data as a regular form based on the record (a person''s project) selected in Subform1. In the On Current event of Subform1 I build an SQL statement to filter the data from the table supporting Subform2. I have confirmed that the SQL statement is properly filtering the data.

Subform2 has numerous unbound text boxes for displaying data relevant to the project selected in Subform1, and the recordset developed by the SQL statement. The data is properly passed to the unbound text boxes on Subform2.

The problem is that if there is no data for the selected project in Subform1 (the recordset is empty), the data from the previously displayed project remains displayed in the unbound text boxes, rather than the text boxes being blanked out.

This is the code I am using to populate the unbound text boxes on Subform2. The complete SQL string is not shown to save space, but it does work properly.

展开 | 选择 | Wrap | 行号

推荐答案

如果不是.EOF而不是.BOF那么

.MoveFirst

请勿.EOF

''遍历所有控件,找到正确的文本框输入数据到

?注意:文本框的标签值是1,2,3?


每个ctl In Forms!frmMain![subform1 control] .Controls

如果ctl.ControlType = acTextBox那么


如果CLng(ctl.Tag)= rsClone!FKxxxID那么


ctl.Value = rsClone!intxxx.Value


''退出循环以节省时间一旦找到

退出

结束如果

结束如果

下一步ctl

.MoveNext

循环
否则

''设置你的未绑定字段=""单独或带循环

结束如果


芯片,


感谢您的评论和评论。我已经尝试了各种各样的方法,但都是徒劳的。这就是我刚刚尝试添加自我声明的地方...
Chip,

Thank you for your review and comments. I''ve tried various ways of what you suggested, all with futility. Here''s what I just tried adding where you put the self statement...
展开 | 选择 | Wrap | 行号


确保您正在引用子窗体控件的名称,而不是每月分配子窗体中的源。
Make sure you are referencing the subform control''s name rather than it''s source in Monthly Allocations Subform.


这篇关于子窗体中的未绑定文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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