how can i populate textbox through VBA in MS Access

。_饼干妹妹 提交于 2019-12-07 02:18:26

问题


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

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


回答1:


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


来源:https://stackoverflow.com/questions/18865201/how-can-i-populate-textbox-through-vba-in-ms-access

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!