Default values using DLookup

sspreyer

Registered User.
Local time
Today, 04:06
Joined
Nov 18, 2013
Messages
251
Hi,
All

I found some code on this forum. That uses DLookup to find the field default value on a form. Is it possible to use this on muitlple fields? Other than copying this code twice and renaming getdefaultTID to getdefaultTID2 for another field

Thanks in advance

Shane



Code:
Function GetDefaultTID() As Long
   GetDefaultTID = Nz(DLookup("YourFieldNameWhichHasTheSetting", "YourSettingsTableHere"), 0)
End Function
 
if you have multiple fields, it may be better to load the 'default' field from a tConfig table.
an query can preload the fields, rather than writing lots o code.
 
if you have multiple fields, it may be better to load the 'default' field from a tConfig table.
an query can preload the fields, rather than writing lots o code.

Thanks ranman

Do you have sample of tconfig table or website with info to make tconfig table.

Thanks a lot

Shane
 
You already have a lookup table called YourSettingsTableHere

Dlookup function has normally 3 parts
(FieldName, Table, Condition)

Your code does not contain a condition, so dlookup will always return the first value in the table in default order

The easiest way to have multiple defaults would be add a field to the lookup table maybe called DefaultName so your lookup table would be

DefaultID DefaultName DefaultValue
1 State CA
2 Color Red
3 Gender Male

To return the default color value use
dlookup("DefaultValue","YourSettingsTableHere","DefaultName='Color'")

NB You need to put single quotes around a text value.
 
its just a table, I call tConfig.
it has the fields I default,
State (OH)
Dept (Acct)

then a new record is started, the append query (or update) adds these 2 fields to the record setting them to the value in tConfig.State and tConfig.Dept.
 
You can set the default in the TABLE. When you add a record to the table, it will apply the value automatically.
ONLY If you want to change the value from the default, then your query must say so.
If your query does not specify a value for the default fields (but the table has this info) then the default will be added automatically.
 
I have gone down the root Cronk was saying thanks alot everyone for the help much appreciated ;)
 

Users who are viewing this thread

Back
Top Bottom