我如何通过VBA在MS Access填充文本框文本框、VBA、MS、Access

2023-09-09 21:24:29 作者:让我再睡一会

我有一个表RR_info其持有以下领域RR_ID,HR_ID,No_of_Beds,Room_Category。现在我想通过VBA code与Form_Load事件我应该填充的文本框为所有这些表字段。为此,我写了获得根据hotel_id作为标准,而是code不工作某些记录的查询。

I have a table RR_info which hold following fields RR_ID, HR_ID, No_of_Beds, Room_Category. Now i want that through VBA code with Form_load event I should populate textboxes for all these table fields. For this I wrote a query which get certain records according to hotel_id as a criteria but code is not working.

Private Sub Form_Load()
Dim SQL As String
Dim db As Database
Dim rs As DAO.Recordset

SQL = "select * from RR_info where hr_id = " & Forms![hhrrr]![List38] & ";"
Set db = CurrentDb
Set rs = db.OpenRecordset(SQL)

Me.RR_ID.Text = rs!RR_ID
Me.HR_ID.Text = rs!HR_ID
Me.Room_No.Text = rs![Room No]
Me.No_of_Beds.text = rs!No_of_Beds
Me.Room_Category.text = rs!Room_Category

Set rs = Nothing
Set db = Nothing

End Sub

这是表中,我想根据通过VBA标准添加表数据的图片

This is the Picture of Table in which i want to add table data according to criteria through VBA

推荐答案

。文属性只适用于目前具有集中控制。当您尝试引用。文上的任何其他控制,你就会触发一个错误。该。价值属性可控制是否具有焦点。

The .Text property is only available for the control which currently has focus. When you attempt to reference .Text on any other control, you will trigger an error. The .Value property is available whether or not the control has focus.

为了安全起见,他们都更改为。价值

To be safe, change them all to .Value.

Me.RR_ID.Value = rs!RR_ID
Me.HR_ID.Value = rs!HR_ID
Me.Room_No.Value = rs![Room No]
Me.No_of_Beds.Value = rs!No_of_Beds
Me.Room_Category.Value = rs!Room_Category