Access中使用参数执行Delete语句

Access中使用参数执行Delete语句

本文介绍了在VBA MS Access中使用参数执行Delete语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在用户单击删除按钮时执行以下Delete语句.

I want the below Delete statement to be executed when the user click the delete button.

CurrentDb.Execute "Delete from [TableName] where ColumnName is not null"

但是我希望用户输入表名和列名.你能帮忙吗

But I want the user to input the tablename and the columnName. Can you please help

推荐答案

这将从表单控件中获取参数:

This will grab parameter from form control:

SELECT *
FROM Customers
WHERE Country = _
  [Forms]![frmSelectCountry]![txtCountry]

这将提示用户输入县" :

SELECT *
FROM Customers
WHERE Country = _
  [Enter Country]

提示用户输入表名,并提示用户输入县名":

To prompt a user for the table name and prompt user to "Enter County":

tblName= InputBox("Please enter a name for the source table", "?")

mysql = "DELETE * FROM " & tblName _
           & "WHERE (((" & tblName & ".[City])=[Enter City]));"

您可以构建一个带有组合框控件(名为"cboTable")的表单(名为"frmSelectTable"),其中列出了可供选择的表,并使代码检索组合框控件的值.

You could build a form (named "frmSelectTable") with a combo box control (named "cboTable") on it listing the tables to choose from and have the code retrieve the combo box controls value.

tblName = [Forms]![frmSelectTable]![cboTable]

与您的工作结合起来:

tblName = InputBox("Please enter a name for the source table", "?")
mysql = "DELETE * FROM " & tblName _
           & "WHERE ColumnName Is Not Null;"
CurrentDb.Execute mysql

这是一个教程,它将引导您逐步完成带有组合框的表单,该组合框列出了数据库中的所有表:如何将所有表名放入组合框

Here is a tutorial that will walk you through making the form that has a combo box listing all the tables in your database:How to Get all Table Names into Combo box

这篇关于在VBA MS Access中使用参数执行Delete语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 07:59