How to show query result in text boxes??

vatralaus

New member
Local time
Today, 10:38
Joined
Jun 25, 2013
Messages
6
Hi
Need some help.
I have query that creates table with 2 records each with 2 columns (2x2) and they do not have indexed ID,and query is related to combo box in other form so results are not always same but it is always (2x2) and value types are always same,

So how to show those results in text box in form,lets say 4 text boxes ,every value in one text box, i assume that i need to use DLookup() but i was able only to show first record,did not know what criteria put to go to second record.

When i select that query and create report i get what i want but i cant copy those text boxes to form that i want.Thx
 
Last edited:
Code:
Set Rs = CurrentDb.OpenRecordset("NameOfYourQuery")
 
i = 1
While (Not Rs.EOF) AND (i + 1 <= TotalNumberOfTextBoxesOnForm)
Forms("YourForm").Controls("TextBox" & i) = Rs("FieldName1")
Forms("YourForm").Controls("TextBox" & i+1)= Rs("FieldName2")
i = i + 2
Rs.MoveNext
Loop

Will fill in controls labeled textbox1, textbox2, ...3 etc.
 
I would probably create a subform based on the query, and put that on the main form. You could make it look the same, and it would be more dynamic in the long run.
 
I would probably create a subform based on the query, and put that on the main form. You could make it look the same, and it would be more dynamic in the long run.

You mean to put button on main form that runs that new query form?
I tried to create form but i got only one record displayed atm (for other click next record) i need them both displayed at same time on main form.
 
Code:
Set Rs = CurrentDb.OpenRecordset("NameOfYourQuery")
 
i = 1
While (Not Rs.EOF) AND (i + 1 <= TotalNumberOfTextBoxesOnForm)
Forms("YourForm").Controls("TextBox" & i) = Rs("FieldName1")
Forms("YourForm").Controls("TextBox" & i+1)= Rs("FieldName2")
i = i + 2
Rs.MoveNext
Loop
Will fill in controls labeled textbox1, textbox2, ...3 etc.

Maybe stupid question,where i need to put these in control source?
 
You mean to put button on main form that runs that new query form?
I tried to create form but i got only one record displayed atm (for other click next record) i need them both displayed at same time on main form.

The form would need to be in Continuous or Datasheet view, then it would show both records.
 
The form would need to be in Continuous or Datasheet view, then it would show both records.

OK i but how to transfer those fields to main form,need them on main form.
I am making handball game statistic database.During game person inputs goals,fouls and so on,so i need score to bee seen on that main form.
(query that i am talking about returns score, 2 team names and 2 team goals number)
 
Create a form based on the query, then use the subform wizard to place that form onto your main form as a subform.
 
Create a form based on the query, then use the subform wizard to place that form onto your main form as a subform.

Thx for info.Can not find that subform wizard ,can you help little more explain how or where to look.
 
It's an icon on the design tab, in the same area as text box, combo box, etc.
 

Users who are viewing this thread

Back
Top Bottom