Form is ignoring the code in OnOpen event

▼魔方 西西 提交于 2019-12-24 09:39:39

问题


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

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.

Thanks jpl


回答1:


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.

Your best way around this is:

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

After that the function can open your bound start form



来源:https://stackoverflow.com/questions/37328423/form-is-ignoring-the-code-in-onopen-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!