Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting the default value in a textbox 1

Status
Not open for further replies.

KalEl33

Programmer
May 20, 2002
17
US
I am having trouble setting the default value in a textbox called txtDate on a form I call frmConfirmUpdate. I want to fill the textbox with the Date from my table called tblData which contains the Date and a unique identifier called MonthlyID. I would like to enter the MonthlyID into a textbox called txtMonthlyID and have the textbox (txtDate) display the corresponding Date. My best guess as to how to do this is to enter the following into the textbox's Default Value property:

=(SELECT [tblData].[Date] FROM [tblData] WHERE ((([tblData].[MonthlyID]) = Me![txtMonthlyID])))

However, I get the following error: #Name?

Any ideas on what I'm doing wrong?

Thanks in advance.
Kal-EL

 
I think you want the DLookup function. Check out the following from Access help.

The following example returns name information from the CompanyName field of the record satisfying criteria. The domain is a Shippers table. The criteria argument restricts the resulting set of records to those for which ShipperID equals 1.

Dim varX As Variant
varX = DLookup("[CompanyName]", "Shippers", "[ShipperID] = 1")


Instead, yours might be: DLookup("[Date]", "tblData", "[MonthlyID]) = " &Me![txtMonthlyID])

Personally, I use Comboboxes in preference to DLookup -- they seem to be much faster. Bind to [MonthlyID] and set Rowsource to a query with the first field MonthlyID and the second [Date].
 
Paron,

Thanks for you help. It worked wonderfully!

Sincerely,
Kal-El
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top