PDA

View Full Version : populate an label from an table



white_flag
07-15-2011, 05:28 AM
Hello

I like to know how can I populate an label.caption from an table

I have this: but it is populated just the first entry from table:


Private Sub Form_Load()
Me.Controls("Label1").Caption = DLookup("[company name]", "companies")
End Sub

hansup
07-16-2011, 07:21 AM
DLookup has an optional third parameter, "criteria", which allows you to specify a subset of the domain ("companies"). The criteria parameter is like the WHERE clause in a query, without the word WHERE.

So if you want the company name for the company whose company_id is 127, you could change the DLookup expression to this:

DLookup("[company name]", "companies", "company_id = 127")

In your situation, you will need to use a criteria string which returns the DLookup value you want instead of the first row it finds in "companies".

white_flag
07-18-2011, 12:49 AM
an DLookup can show all the records from an column (table: companies, columns: company_names; location ...etc)

all the records from column company_names

HiTechCoach
07-18-2011, 05:41 PM
DLookup() only returns a value from a single record. If you do not use any criteria to identify the specific record then it returns the first one found.

If you want to return the value from multiple records then it is best to use VBA code to open a recordset an loop through the records.

white_flag
07-19-2011, 07:03 AM
and what will be an starting code? for open an recordset an loop through the records?

I attached something like an database for an better understanding (from me)
In my case I have some records that are having the same date. I like to be displayed all records from that date not just the first one

HiTechCoach
07-19-2011, 09:27 AM
If you need to show multiple records then why not use a sub form?