UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Domain Function Usage Samples, Any Version    
 
   
CyberCow
post May 30 2002, 09:49 PM
Post#1


UdderAccess Admin + UA Ruler
Posts: 19,555
Joined: 27-April 02
From: Upper MI


Domain Function Usage Samples

This applies to Domain Aggregate Functions: DAvg, DCount, DFirst, Dlast, DLookup, DMax, Dmin, DstDev, DstDevP, DSum, DVar, DVarP

Criteria could be a key or other field


Typical Use

Numerical values:
CODE
DLookup("[FieldName]" , "TableName" , "[Criteria] = n")


Strings: *a single quote before and after the value
CODE
DLookup("[FieldName]" , "TableName" , "[Criteria]= 'string'")


Dates:
CODE
DLookup("[FieldName]" , "TableName" , "[Criteria]= #date#")


Referring to a control on a form

Numerical values:
CODE
DLookup("[FieldName]", "TableName", "[Criteria] = " & forms!FormName!ControlName)


Strings: *single quote before and after the value
CODE
DLookup("[FieldName]", "TableName", "[Criteria] = '" & forms!FormName!ControlName & "'")


Dates:
CODE
DLookup("[FieldName]", "TableName", "[Criteria] = #" & forms!FormName!ControlName & "#")


Combinations
CODE
DLookup("[FieldName]", "TableName", "[Criteria1] = " & Forms![FormName]![Control1]  _
             & " AND [Criteria2] = '" & Forms![FormName]![Control2] & "'" _
            & " AND [Criteria3] =#" & Forms![FormName]![Control3] & "#")
Go to the top of the page
 
-Scott-
post May 30 2002, 10:35 PM
Post#2


UA Quasi Admoderuser
Posts: 2,256
Joined: 30-January 00
From: Windsor, ON, Canada


In addition to CyberCow's post, you can use expressions in them as well. For example:

To grab 2 field values from a single record:
CODE
stringVar = DLookup("[LastName] & ', ' & [FirstName]", "tblPeople", "[PrimaryKey] = 7")



You can also use mathematical expressions:
CODE
numericVar = DLookup("[Field1] + [Field2]", "tableName", "[PrimaryKey] = 7")



FOr even, use control structures:
CODE
stringVar = DLookup("IIf([LastName] Like 'Smith', 'True', 'False')", "tableName", "[PrimaryKey] = 7")
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    16th December 2017 - 07:20 PM