Try to set values of a text box thru code

E

Eric

I try to to set the value of a text box through code and it will always
display the same value in every record. I think i cant display a
recordset in a text box. What way i use so that i can display my values
in the text box.

Private Sub Form_Open(Cancel As Integer)
Dim qry As String, rst As Object
qry = "SELECT tbl_EquipmentChronology.Equipment1 FROM
tbl_EquipmentChronology INNER JOIN tbl_events ON
tbl_events.TicketNum=tbl_EquipmentChronology.TicketNum where
tbl_events.TicketNum=" &
Forms!tbl_PPVResearch_Edit!frm_Events!TicketNum & " and
tbl_events.PPVVOD_Outlet=tbl_EquipmentChronology.Outlet"
Set rst = CurrentDb.OpenRecordset(qry)
rst.MoveFirst
Do While Not rst.EOF
Forms!tbl_PPVResearch_Edit!frm_Events![Text2] = rst!Equipment1
rst.MoveNext
Loop
End Sub
 
B

Brendan Reynolds

It's possible to loop through a recordset and concatenate values into a
string, and display that string in a text box. More commonly, however, list
boxes or subforms in continuous forms or datasheet view are used to display
multiple records.
 
E

Eric

This unbound textbox in a continuous form really give me a hard time
since two days. Now i try it in another way. I create a query in a
query designer name query5 and in the control source of textbox name
text2(unBound) wrote the following

=[Query5]![Equipment1]:

Query5
SELECT tbl_EquipmentChronology.Equipment1, tbl_Events.PPVVOD_Outlet,
tbl_EquipmentChronology.Outlet, tbl_Events.TicketNum
FROM tbl_Events INNER JOIN tbl_EquipmentChronology ON
(tbl_Events.TicketNum = tbl_EquipmentChronology.TicketNum) AND
(tbl_Events.PPVVOD_Outlet = tbl_EquipmentChronology.Outlet) WHERE
(((tbl_Events.TicketNum)=" &
Forms!tbl_PPVResearch_Edit!frm_Events!TicketNum & and
tbl_events.PPVVOD_Outlet=tbl_EquipmentChronology.Outlet"));

But this time it print these values in the form

#Name?
#Name?
#Name?

I need only the display in text2 box thats why i didnt bind with the
table.

Thanks in advance.


Brendan said:
It's possible to loop through a recordset and concatenate values into a
string, and display that string in a text box. More commonly, however, list
boxes or subforms in continuous forms or datasheet view are used to display
multiple records.

--
Brendan Reynolds
Access MVP

Eric said:
I try to to set the value of a text box through code and it will always
display the same value in every record. I think i cant display a
recordset in a text box. What way i use so that i can display my values
in the text box.

Private Sub Form_Open(Cancel As Integer)
Dim qry As String, rst As Object
qry = "SELECT tbl_EquipmentChronology.Equipment1 FROM
tbl_EquipmentChronology INNER JOIN tbl_events ON
tbl_events.TicketNum=tbl_EquipmentChronology.TicketNum where
tbl_events.TicketNum=" &
Forms!tbl_PPVResearch_Edit!frm_Events!TicketNum & " and
tbl_events.PPVVOD_Outlet=tbl_EquipmentChronology.Outlet"
Set rst = CurrentDb.OpenRecordset(qry)
rst.MoveFirst
Do While Not rst.EOF
Forms!tbl_PPVResearch_Edit!frm_Events![Text2] = rst!Equipment1
rst.MoveNext
Loop
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top