将查询结果传递到访问表单上的文本框控件 [英] Passing query result to a textbox control on an access form

查看:101
本文介绍了将查询结果传递到访问表单上的文本框控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要有关Access 2007表单上的文本框字段的帮助.我试图将查询的结果插入到窗体上的文本框控件中.这仅用作用户的信息.该表格向查询提供参数以获取值.该查询工作正常,并返回正确的结果.我似乎无法弄清楚的是如何将查询结果传递给文本框.我尝试了几种不同的方法,但是没有运气.

I need help with a textbox field on an Access 2007 form. I'm trying to insert the result of a query into the text box control on the form. This is used soley as information for the user. The form supplies the query with parameters to get the value. The query works fine and returns the correct result. What I can't seem to figure out is how to pass the query result to the textbox. I’ve tried several different ways but with no luck.

(PS)我知道一个组合框可以进行查找,但是我不希望用户单击下拉列表只是为了选择该值,因为从查询中只能得到一个值结果.因为我不是程序员或数据库管理员,所以我乐于接受建议,但是我已经在Access上上了几节课(足够危险了).

(PS> I know a combo box can do a lookup, however I don’t want the user to have to click the dropdown just to select the value as there can only ever be one value result from the query.) I'm open to suggestions as I'm not a programmer or DB Admin, but I've taking a few classes on Access (enough to be dangerous).

Private Sub cbo3_Change()
Me.tbx2 = ("SELECT tbl_Billing.Savings_b FROM tbl_Billing GROUP BY tbl_Billing.UBI_b, tbl_Billing.TaxYr_b, tbl_Billing.TaxPrg_b, tbl_Billing.Savings_b HAVING (((tbl_Billing.UBI_b)=forms!f1_UpBilled!cbo1) And ((tbl_Billing.TaxYr_b)=forms!f1_Upbilled!cbo2) And ((tbl_Billing.TaxPrg_b)=forms!f1_UpBilled!cbo3));")

End Sub

推荐答案

如果您希望在运行时执行此操作,则需要执行以下操作,我采用的是相同格式的控件.

If you wish to do this in run time, you need to do the following, I take the controls you are referring to in this is on the same form.

完成它的非常简单直接的方法如下,

The very simple and straight forward way to get it done is as follows,

Private Sub cbo3_Change()
    Dim tmpRS As DAO.Recordset

    Set tmpRS = CurrentDb.OpenRecordset("SELECT tbl_Billing.Savings_b FROM tbl_Billing GROUP BY " & _
                                        "tbl_Billing.UBI_b, tbl_Billing.TaxYr_b, tbl_Billing.TaxPrg_b, " & _
                                        "tbl_Billing.Savings_b HAVING ((tbl_Billing.UBI_b = '" & Me.cbo1 & "') And (tbl_Billing.TaxYr_b = '" & Me.cbo2 & "') " & _
                                        "And (tbl_Billing.TaxPrg_b = '" & Me.cbo3 & "'))")
    If tmpRS.RecordCount > 0 Then
        Me.tbx2 = tmpRS.Fields(0)
    Else
        Me.tbx2 = 0
    End If

    Set tmpRS = Nothing
End Sub 

请注意,我暗示您所有的组合框都返回 String ,而您要比较的字段是 Text 类型.如果不是这种情况,则需要进行相应的更改.

Just note, I have implied all your combo boxes are returning String and the field you are comparing against are Text type. If that is not the case, you need to make changes accordingly.

这篇关于将查询结果传递到访问表单上的文本框控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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