本文介绍了如何在Access VBA中使用SQL SELECT语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个组合框,想要将其值与SQL WHERE子句一起使用.如何根据组合框值在VBA中运行一个SELECT语句?
I have a combobox whose value I want to use with a SQL WHERE clause. How do you run a SELECT statement inside VBA based on the combobox value?
推荐答案
如果您想使用绑定列的值,只需引用组合即可:
If you wish to use the bound column value, you can simply refer to the combo:
sSQL = "SELECT * FROM MyTable WHERE ID = " & Me.MyCombo
您还可以引用column属性:
You can also refer to the column property:
sSQL = "SELECT * FROM MyTable WHERE AText = '" & Me.MyCombo.Column(1) & "'"
Dim rs As DAO.Recordset
Set rs = CurrentDB.OpenRecordset(sSQL)
strText = rs!AText
strText = rs.Fields(1)
在文本框中:
= DlookUp("AText","MyTable","ID=" & MyCombo)
*已编辑
这篇关于如何在Access VBA中使用SQL SELECT语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!