Populate a textbox via a query

G

Guest

I have a table of records with 3 fields: Name, Date, Number. Every 3 records
will have the same name and therefore will have a 1,2, or 3 in the Number
field. I have a form with 3 textboxes to show this info. I would like to
put the date of the record with a "1" in the number field in the first
textbox, the record with a "2" will have it's date in the 2nd textbox, etc.
I was trying to have a command button execute 3 different queries to do
this - without success. Question: can you execute a query in the click event
of a command button? If so, what is the code? (or is there a better way?)

Nick
 
U

UpRider

sub cmdButton_Click
txtField1 = DLookup("theData", "tblNames", "theNumber =" & 1 &" and
theName = " & Chr$(39) & txtName & Chr$(39) )
txtField2 = DLookup("theData", "tblNames", "theNumber =" & 2 &" and
theName = " & Chr$(39) & txtName & Chr$(39) )
txtField3 = DLookup("theData", "tblNames", "theNumber =" & 3 &" and
theName = " & Chr$(39) & txtName & Chr$(39) )
End Sub

txtField1,2,3 are the textboxes that hold the data you wish to display on
your FORM
theData is the field name in the TABLE that you are looking up
tblNames is the name of the TABLE holding the data
theName is the name of the FIELD in the TABLE holding the target name
theNumber is the name of the FIELD in the TABLE that holds the 1, 2, or 3
txtName is a control on your FORM holding the name that you looking up data
for

This code must appear in a FORMS module.
If you display the fields in this way you CANNOT update them on this form.
This is aircode. May need adjustments.
If theNumber is actually a text field, surround the 1,2,and 3 with the &
Chr$(39) pairs;
i.e ......"theNumber =" & chr$(39) & 1 & chr$(39) & " and theName="........

HTH
UpRider
 

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