简体   繁体   English

ms access vba 表单、文本框、查询

[英]ms access vba forms, textboxes, queries

I am fairly new here.我在这里很新。

I am using access 2013 with vba only, no macros.我只使用带有 vba 的 access 2013,没有宏。

One table called tblStoreCode with three fields, one being the autonumber, the others are fldStoreCode and fldStoreName.一个名为 tblStoreCode 的表具有三个字段,一个是自动编号,其他是 fldStoreCode 和 fldStoreName。

My form called frmStoreDetails has two textboxes, txtStoreCode and txtStoreName and a cmdSearch button.我的名为 frmStoreDetails 的表单有两个文本框、txtStoreCode 和 txtStoreName 以及一个 cmdSearch 按钮。

What I would like is when a user enters a code into txtStoreCode and clicks the button then the sql statement must look at the value in txtStoreCode and then look in tblStoreCode, find the Code and then display the Store Name in txtStoreName on the form.我想要的是当用户在 txtStoreCode 中输入代码并单击按钮时,sql 语句必须查看 txtStoreCode 中的值,然后查看 tblStoreCode,找到代码,然后在表单上的 txtStoreName 中显示商店名称。

I tried so far我试过到目前为止

Private Sub Command9_Click() 
Dim MyString As String 
MyString = CurrentDb.QueryDefs("qryStore").OpenRecordset.Fields("fldStoreName")
Me.txtName.SetFocus txtName.Text = MyString End Sub 

Please help.请帮忙。

This how i was doing it-我是这样做的-

Private Sub cmdSearch_Click() 
    txtName = nz(Dlookup("fldStoreName","tblStoreCode","aa=" & nz(txtStoreCode,0)),"")
End Sub

Or like this if the nz function Complicates you (nz function will help prevent problems when there is null value)或者,如果 nz 函数使您复杂化(nz 函数将有助于防止出现空值时出现问题)

Private Sub cmdSearch_Click() 
    txtName = Dlookup("fldStoreName","tblStoreCode","aa=" & txtStoreCode,0)
End Sub

Have fun!玩得开心!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM