无法识别两种表格中的一种是否开放 [英] Access not recognizing if one of two forms is open or not

查看:63
本文介绍了无法识别两种表格中的一种是否开放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我正在尝试在表单关闭时编写代码。它应该重新查询一个组合框,具体取决于当前表单后面的背景中当前打开的形式,如下所示:


Private Sub Form_Close()


如果表格(frmProjecTotal).CurrentView<> 0然后

表格![frmProjectsTotal]![cboCity] .Requery

Else

表格![frmProjectsSearch]![cboCity] .Requery

结束如果


结束子


如果frmProjectsTotal在此表单后面打开,那么它应该重新查询组合框在那个表格上。如果它没有打开,这意味着frmProjectsTotal在这个表单后面打开,应该重新查询该表单上的组合框。在任何给定的时间,只有一个frmProjectsTotal或frmProjectsSearch被打开。


此代码适用于在打开时重新获取frmProjectsTotal,但是当它被重新查询frmProjectsSearch时不起作用这是开放的形式。它给出了一个错误信息,它找不到frmProjectsTotal。我不明白;这就是代码应该做的事情:当然它找不到frmProjectsTotal,那是因为在这种情况下,它不是开放的。


我觉得我的代码可能有问题。

有什么建议吗?


谢谢,


Wayne。

Hi,

I''m trying to write code for a form when it closes. It''s supposed to requery a combo box depending on which form is currenlty open in the background behind the current form, shown below:

Private Sub Form_Close()

If Forms(frmProjecTotal).CurrentView <> 0 Then
Forms![frmProjectsTotal]![cboCity].Requery
Else
Forms![frmProjectsSearch]![cboCity].Requery
End If

End Sub

If frmProjectsTotal is open behind this form, then it should requery the combo box on that form. If it''s not open, that means frmProjectsTotal is open behind this form and should requery the combo box on that form instead. At any given time either only one of frmProjectsTotal or frmProjectsSearch is open.

This code works for requerying frmProjectsTotal when it''s open, but it won''t work for requerying frmProjectsSearch when that''s the form that is open. It gives an error message that it can''t find frmProjectsTotal. I don''t understand it; this is what the code is supposed to do: of course it can''t find frmProjectsTotal, that''s because in this condition, it''s not open.

I think my code might be wrong.
Any suggestions?

Thanks,

Wayne.

推荐答案

我发现这是A中的一个痛苦...我认为你必须备份到文件集或其他东西如果它没有打开就可以访问该表单(如果不是,那么代码会因为你找到而崩溃)。


或者,您可以调用自己的错误处理并对其进行测试:

On Error Resume Next

i = Forms(frmProjecTotal ).CurrentView

如果Err = 0那么

表格![frmProjectsTotal]![cboCity] .Requery

Else

表格![frmProjectsSearch]![cboCity] .Requery

结束如果

错误转到0

(免责声明:我没有''' t测试这段代码!)


或者你可以只调用Forms(2).Name并运行你的If语句吗?


詹姆斯
I find this a pain in the A ... I think you have to back up to the documents collection or something like that to access the form if it''s not open (and if it''s not, the code will crash as you have found).

Alternatively, you could invoke your own error handling and test against that :
On Error Resume Next
i= Forms(frmProjecTotal).CurrentView
If Err=0 Then
Forms![frmProjectsTotal]![cboCity].Requery
Else
Forms![frmProjectsSearch]![cboCity].Requery
End If
On Error Goto 0
(DISCLAIMER: I didn''t test this code!)

or maybe you could just call out Forms(2).Name and run your If statement against that?

James


嗯还在工作。我做了一些错误检查,弹出错误对话框,告诉我程序输入了哪个条件。无论打开哪个表单,程序将始终进入第一个条件,它永远不会进入else条件(即使frmProjectsTotal未打开)。嗯... .......


还有什么建议吗?
hmmmm still workin at it. I did some error checking with error dialog boxes that pop up telling me which conditition the program entered. No matter which form is open, the program will always enter into the first condition, it never enters the else condition (even when frmProjectsTotal is not open). hmmmmm.............

hmmm

any more suggestions?


将表单名称传递给Global变量,然后使用它来决定重新查询哪个组合框。


Mary
Pass the form name to a Global variable and then use that to decide which combobox to requery.

Mary


这篇关于无法识别两种表格中的一种是否开放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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