表单忽略了OnOpen事件中的代码 [英] Form is ignoring the code in OnOpen event

查看:114
本文介绍了表单忽略了OnOpen事件中的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

具有一个包含控件的新表单,该表单已链接到SQL Server中的表.拥有可在打开时重新链接表的代码,并且该代码可在其他5个应用程序中使用,但不适用于此应用程序.这是代码:

Have a new form that contains controls and is linked to a table in SQL Server. Have code that relinks the table on open, and that code works in 5 other apps, but not this one. Here is the code:

  Dim tdf As DAO.TableDef
  For Each tdf In CurrentDb.TableDefs
  ' check if table is a linked table
  If Len(tdf.Connect) > 0 Then
  tdf.Connect = "Connect String"
  tdf.RefreshLink
  End If
  Next

我在应用程序激活时在选项中设置了表单,以打开它,但它要求输入连接字符串中的密码.我在in open事件中已在一行代码上输入了停止符,但该代码从未执行.就像onopen事件被忽略一样.

I had the form set up in options to open when the app is activated, but it ask for the password which I have in the connect string. I have entered a stop on a line of code in the in open event, but that code never executes. It's like the onopen event is being ignored.

谢谢 jpl

推荐答案

Access要在On Open事件运行之前加载绑定形式的数据.我猜在您的其他应用程序中,起始表格是未绑定的.

Access wants to load the data of a bound form before the On Open event runs. I guess in your other applications the start form is unbound.

您最好的解决方法是:

创建一个

Create an AutoExec macro that calls a public function with your relink code.

此后,该函数可以打开您的绑定开始表单

After that the function can open your bound start form

这篇关于表单忽略了OnOpen事件中的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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