没有数据时子窗体不显示 [英] Subform not showing when there is no data

查看:231
本文介绍了没有数据时子窗体不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于MS SQL Server通过ODBC的Access 2010数据库。有时我会打开一个包含子表单的表单,然后我将转到当前记录的相关表中没有数据的记录,子表单将不在那里。控件的框在那里,但子窗体不是。这并不总是会发生,这使我很难弄清楚什么是使其有效而不是另一次有效的共同点。当我使用Access作为后端时,我从来没有遇到过这样的麻烦,所以我假设有一些MS SQL Server或只是一般的ODBC连接导致这种情况。


这种情况​​持续发生的一个例子是当我添加用户时,子表单只有在某种类型的用户时才可见。首次创建用户时,我将子表单设置为visible = False。在EmployeeType组合框'的AfterUpdate事件中,我检查选择的类型是否是需要此子表单的类型,如果是,则我使子表单可见。发生这种情况时,只有子窗体控件变为可见,而不是窗体(这是空的,这是输入的新员工)。我必须转到另一个员工的记录,然后回到我刚创建的那个记录,然后我看到子表单本身,并可以添加其中所需的数据。每次都会发生这种情况另一种情况是在不同的表单上有一个子表单,其Visible属性永远不会改变,但有时它是不可见的。到目前为止,只有在没有数据时才会发生这种情况。


即使没有数据,我能做些什么才能使这些子表格始终可见?

I have an Access 2010 database that is based on MS SQL Server through ODBC. There are a some times when I will open a form that has a subform and I will go to a record where there is no data in the related table for the current record and the subform will not be there. The box for the control is there, but the subform is not. This doesn''t always occur, which makes it tough for me to figure out what is the common denominator that makes it work once and then not another time. I have never had trouble with this when using Access as the backend so I''m assuming that there is something with either MS SQL Server or just ODBC connections in general that is causing this.

One example of this happening consistently is when I add a user, the subform is only visible if they are a certain type of user. When first creating the user, I have the subform set to visible = False. In the EmployeeType combobox''s AfterUpdate event I check to see if the type selected was the type that needs this subform and if it is, then I make the subform visible. When this happens, only the subform control become visible, but not the form (which is empty this this is a new employee being entered). I have to go to another employee''s record and then come back to the one I just created and then I see the sub form itself and can add the data needed in it. This happens every time. There is another situation with a subform on a different form whose Visible property never changes, but occasionally it isn''t visible. So far this only occurs when there is no data.

Is there something that I can do to make these subforms always be visible even if there is no data?

推荐答案

嗯,当链接表在MS SQL中没有唯一索引时,我遇到了麻烦。所以首先检查或子窗体的表有这样一个独特的索引。

接下来确保设置子窗体的dataentry属性。


我个人而已通常将子窗口插入子窗体的表(使用mainform的ID)以允许用户轻松更新,但是当用户取消对mainform的INSERT时,这需要DELETE。在您的情况下,类型的选择可以触发这样的INSERT。


Nic; o)
Hmm, I''ve run into trouble when the linked table doesn''t have a unique index in MS SQL. So first check or the subform''s table has such a unique index.
Next make sure the dataentry property for the subform is set.

Personally I often INSERT a childrow into the subform''s table (with the mainform''s ID) to allow easy update by the user, however this requires a DELETE when the user cancel the INSERT of the mainform. In your case the selection of the Type can trigger such an INSERT.

Nic;o)


两个表(对于父和子表单)已设置主键。


当您说确保子表单的dataentry属性已设置时我假设你的意思是设置为否(它是)。否则,现有数据不会显示。


您自动将哪些数据放入子表单中?我认为这会导致用户在主窗体中创建记录时产生混淆,然后子窗体中已有记录。
Both tables (for the parent and subform) have primary keys set.

When you say, "make sure the dataentry property for the subform is set" I assume you mean set to no (which it is). Otherwise, existing data isn''t shown.

What data do you put in the subform automatically? I picture this causing confusion for my users when they create a record in the main form and then there is already a record in the subform.


Dataentry本身应该是No,但是你需要允许添加课程记录。


我在选择类型时触发INSERT图片。当类型发生变化时,这也需要DELETE,但有效地添加成为现有记录的更新,这种方法为我节省了大量时间来寻找记录不会出现的原因。

可能我会拆分 mainform和子表单中包含一个带有所有Employees数据表子表单的mainform,以及不同的操作按钮,例如:

添加TypeA

添加TypeB等。

更新

删除

打印



因此当点击[员工添加TypeA ]按钮,您可以显示带有或不带子表单的正确表单。


与员工一起使用这样的主表单将允许用户使用右键单击弹出菜单来轻松过滤员工找到需要更新的一个(s)。这种方法在许多应用中相当普遍。


Nic; o)
Dataentry itself should be "No", but you need to allow addition of records ofcourse.

I picture triggering an INSERT when the Type is selected. This also requires a DELETE when there''s a change of Type, but effectively the addition becomes an Update of an existing record and this approach saved me a lot of time looking for why records don''t appear.

Possibly I would "split" the mainform and the subform in having a mainform with a datasheet subform with all Employees and besides that different action buttons like:
Add TypeA
Add TypeB, etc.
Update
Delete
Print
etc.
Thus when clicking the [Employee Add TypeA] button you can show the proper form with or without the subform.

Having such a mainform with employees will allow the user to use the right-click popup menu to filter the employees and easily find one(s) that needs to be updated. And this approach is rather common in many applications.

Nic;o)


这篇关于没有数据时子窗体不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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