退出按钮的VBA代码 [英] VBA Code for Exit Button

查看:944
本文介绍了退出按钮的VBA代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了以下代码,以便在表单的"退出"按钮上运行。

I have created the following code to run on an Exit button for a form.

Private Sub cmdExit_Click()

DoCmd.SetWarnings False

On Error Resume Next

Private Sub cmdExit_Click()
DoCmd.SetWarnings False
On Error Resume Next

DoCmd.OpenQuery" ApplicationAccesswithoutUserApps",acViewNormal,acReadOnly'运行应用程序无用户查询

DoCmd.OpenQuery "ApplicationAccesswithoutUserApps", acViewNormal, acReadOnly ' run the Application Without User Query

DoCmd.OpenQuery" AppendUserApps",acViewNormal,acReadOnly'运行AppendUserApps查询

DoCmd.OpenQuery "AppendUserApps", acViewNormal, acReadOnly ' run the AppendUserApps Query

DoCmd.Close acForm," ApplicationAccess",acSaveNo'关闭应用程序访问表单

DoCmd.Close acForm, "ApplicationAccess", acSaveNo 'Close the Application Access Form

DoCmd.SetWarnings True

End Sub

DoCmd.SetWarnings True
End Sub

问题是查询正在创建新记录在数据库中第一条记录的子表单中。

The problem is the query is creating a new record in the sub-form for the first record in the database.

我有一个带有子表单的表单。 主要表单用于查看当前记录或添加新记录,子表单显示用户的所有当前相关记录。

I have a form with a sub-form.  The main form is for viewing current records or adding a new record and the sub-form shows all currently related records for a user.

表单包含UserName,Department,Application,Supervisor,Removal日期字段。

The form has UserName, Department, Application, Supervisor, Removal Date fields.

子表单包含UserName和Application字段。

The sub-form has UserName and Application fields.

为什么Exit按钮代码为第一条记录创建新的空白记录在我的主表中?

Why is the Exit button code creating a new blank record for the first record in my main table?

推荐答案

嗨。看起来像查询"AppendUserApps"可能正在为您添加记录。关闭表单时是否必须运行它?如果是这样,您可以查看查询以确保它正在执行它应该执行的操作。只是一个想法......
Hi. Looks like the query "AppendUserApps" might be adding the record for you. Do you have to run it when closing the form? If so, you might review the query to make sure it's doing what it's supposed to do. Just a thought...


这篇关于退出按钮的VBA代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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