feeding textbox with query results

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.
 
J

Jeanette Cunningham

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
 
A

Alejandro

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.
 

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

Top