Find and Display Contents of Field in 1st Record

K

Kirk P.

I've got a switchboard form that opens upon opening of my database. I want
to display the ImportDate contained in tblCombinedData on this switchboard
form.

I'm looking for the VBA code that would open tblCombinedData, move to the
first record, and display the contents of a field called ImportData in a text
box called txtImportData. I believe this would run much faster than my
SELECT DISTINCT SQL query, which works, but runs too slowly over the network.

Thanks!
 
M

Marshall Barton

Kirk said:
I've got a switchboard form that opens upon opening of my database. I want
to display the ImportDate contained in tblCombinedData on this switchboard
form.

I'm looking for the VBA code that would open tblCombinedData, move to the
first record, and display the contents of a field called ImportData in a text
box called txtImportData. I believe this would run much faster than my
SELECT DISTINCT SQL query, which works, but runs too slowly over the network.

You only want to get the value from the first record in the
table??

If the table has more than one record, there is no such
thing as the "first" record. Tables are an unordered bag of
data. OTOH, if you have a field that defines "first" (e.g.
a date field), then you could use a query such as:

SELECT TOP 1 ImportDate
FROM tblCombinedData
ORDER BY datefield

If the table only has one record, then a simple DLookup
should be sufficient:

DLookup("ImportDate", "tblCombinedData")
 
M

Marshall Barton

ALL the records have the same value in that field? Sounds a
little strange to me, but I guess I don't need to go into
that. Whatever!

Your idea would be viable and the syntax would be something
like:
Me.textbox = rs!ImportDate
A MoveFirst is not needed. First, because that's where the
recordset is positioned when it's opened and second because
you don't care what record you get the value from.

Actually, since it doesn't matter what record the value
comes from, you can just use a text box expression:
=DLookup("ImportDate", "tblCombinedData")
or
=DFirst("ImportDate", "tblCombinedData")
both of which will get the value from an arbitrary record,
not necessarily what you might think is the "first".
 

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