feeding textbox with query results

  • Thread starter Thread starter Alejandro
  • Start date Start date
A

Alejandro

Hello there,

I'm creating a form which based on the user entries (in combo boxes in that
form) executes one query out of a group of 6 queries. The results, though,
are pretty much the same for all queries: a single line with two columns, one
for the name of a code and another one with the average charges for that code.

I don't want to have 6 different subforms in my main form, so I was thinking
that it would be better if I somehow could take the value of the code column
and link it to a text box and the value of the average and link it to another
text box. That way the same two textboxes would be updated based on the query
that was run.

Hope that I made myself clear, and that someone out there can give me a hand.

Thanks,

AP.
 
Alejandro,
you can use DLookup to get the value from a saved query into a text box.

One idea is to use the after update event of the combo box something like
this:

Private Sub NameOfCombo_AfterUpdate()
Dim strCriteria as String

Me.NameOfTextBox = DLookup("[TheField]", "QueryName", strCriteria)

End Sub

Use vba help on DLookup to get it working.
You will need code to choose the appropriate query based on the items user
selects in the combo boxes.

Note - replace NameOfCombo, NameOfTextBox , TheField, QueryName with the
appropriate values for your form


Jeanette Cunningham -- Melbourne Victoria Australia
 
Thanks Jeanette!!

Jeanette Cunningham said:
Alejandro,
you can use DLookup to get the value from a saved query into a text box.

One idea is to use the after update event of the combo box something like
this:

Private Sub NameOfCombo_AfterUpdate()
Dim strCriteria as String

Me.NameOfTextBox = DLookup("[TheField]", "QueryName", strCriteria)

End Sub

Use vba help on DLookup to get it working.
You will need code to choose the appropriate query based on the items user
selects in the combo boxes.

Note - replace NameOfCombo, NameOfTextBox , TheField, QueryName with the
appropriate values for your form


Jeanette Cunningham -- Melbourne Victoria Australia


Alejandro said:
Hello there,

I'm creating a form which based on the user entries (in combo boxes in
that
form) executes one query out of a group of 6 queries. The results, though,
are pretty much the same for all queries: a single line with two columns,
one
for the name of a code and another one with the average charges for that
code.

I don't want to have 6 different subforms in my main form, so I was
thinking
that it would be better if I somehow could take the value of the code
column
and link it to a text box and the value of the average and link it to
another
text box. That way the same two textboxes would be updated based on the
query
that was run.

Hope that I made myself clear, and that someone out there can give me a
hand.

Thanks,

AP.
 
Back
Top