473,382 Members | 1,238 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,382 developers and data experts.

Access Built-in Functions

MMcCarthy
14,534 Expert Mod 8TB
Access has a number of built-in functions which can be generally used in queries or VBA code. Some of the more common ones are:

Note: anything in square brackets [] is optional

Date Functions

Date() - Returns the current system date

Now() - Returns the current system timestamp (date and time)

Year(dateValue) - Returns the 4 digit year of any given date

Month(dateValue) - Returns the month number of any given date

MonthName(number, [abreviate]) - Returns the monthname for any given number 1 - 12, putting true in the [abreviate section will abreviate the month name. The default is false. To get the month name of any given date this function would have to be used in conjunction with the previous function. e.g. MonthName(Month(dateValue))

Weekday(dateValue, [FirstDayofWeek]) - Returns the day of the week of any given date value 1-7. The first day of the week can be set e.g. vbMonday. The default is Sunday.

WeekdayName(number, [abbreviate], [firstdayofweek]) - Returns the weekday name of any given number. To get the weekday name of a given date this function can be used in conjunction with the previous one. e.g. WeekdayName(Weekday(dateValue))

Day(dateValue) - Returns the day of the month (1-31) of any given date value.

DateSerial(year, month, day) - Returns a date for any given year, month and day

Time() - Returns the current system time

Hour(timeValue) - Returns the hour value of any given time or timestamp

Minute(timeValue) - Returns the minute value of any given time or timestamp

Second(timeValue) - Returns the second value of any given time or timestamp

For the following functions you will need to know what intervals are:
Expand|Select|Wrap|Line Numbers
  1. Value  Description
  2. yyyy   Year
  3. q      Quarter                                         
  4. m      Month                                         
  5. y      Day of the year                                         
  6. d      Day                                         
  7. w      Weekday                                         
  8. ww     Week                                         
  9. h      Hour                                         
  10. n      Minute                                         
  11. s      Second
  12.  
DateAdd(interval, number, dateValue) - Returns the new date value after the addition of a number of specified intervals. e.g. DateAdd("yyyy", 3, #01/05/2001#) would return "01/05/2004"

DateDiff(interval, dateValue1, dateValue2, [firstdayofweek], [firstweekofyear]) - Returns the difference in the specified interval between two given dates. e.g. DateDiff("yyyy", #01/05/2001#, #02/07/2006#) would return 5. firstdayofweek is optional. It specifies the first day of the week. Access assumes that Sunday is the first day of the week. firstweekofyear is optional. It specifies the first week of the year. Access assumes that the week containing Jan 1st is the first week of the year.

DatePart(interval, dateValue, [firstdayofweek], [firstweekofyear]) - Returns the specified part of any given date. e.g. DatePart("yyyy", #02/07/2005#) would return 2005.

Number Functions

The following are normally used in SELECT queries known as aggregate queries. Please note if other fields are also returned by the query then the results will be grouped on those field values.

Avg(fieldName) - Returns the average of a series of values in a given field

Count(fieldName) - Returns the total number of records returned by a query

Sum(fieldName) - Returns the sum of a series of values in a given field

Max(fieldName) - Returns the largest of a series of values in a given field

Min(fieldName) - Returns the smallest of a series of values in a given field

The following can be used in queries or VBA code.

Int(numberValue) - Returns the integer part of any given number. Please note this will not round a number up to the nearest integer.

Round(numberValue, [decimal places) - Returns a number rounded to the specified number of decimal places. If the decimal places is left blank then the default is 0 which means an integer is returned. The Round function behaves a little unexpectedly as it uses round-to-even logic. If the number that you are rounding ends with a 5, the Round function will round the expression so that the last digit is an even number.
For example:
Round(22.35, 1) would return 12.4 (rounds up)
Round(22.65, 1) would return 12.6 (rounds down)
Round(22.75, 1) would return 12.8 (rounds up)

Val(stringValue) - Returns any numbers found in a string

String Functions

Instr([start position], StringBeingSearched, StringSearchedFor, [compare]) - Returns the position number in the string being searched of the string or character being searched for. The start position will default to position 1 (the start of the string). The compare is for the type of comparison to perform. The valid choices are vbUseCompareOption, vbBinaryCompare, vbTextCompare, and vbDatabaseCompare.

Len(StringValue) - Returns the number of characters in a given string. This will include spaces.

Left(stringValue, Number of characters) - Return a substring of the required length starting at the left of the string.

Right(stringValue, Number of characters) - Return a substring of the required length starting at the right of the string.

Mid(stringValue, Start Postion, Number of characters) - Return a substring of the required length starting at the given start position in the string.

Domain Aggregate Functions (functions which lookup values in a table or query)

DLookup (expression, domain, [criteria]) - Returns a single value found.In expression normally you would put a field name however it can also be a calculation. For domain you would put the table name or query name. Criteria is optional. Think of it as the WHERE clause. e.g. DLookup("OrderDate", "Orders", "OrderID = 10248")

DCount (expression, domain, [criteria]) - Returns the number of records in a table or query based on the criteria given. Criteria is optional.

DMax (expression, domain, [criteria]) - Returns the maximun value in the specified field.

DSum (expression, domain, [criteria]) - Returns the sum of values in a specified field or calculated expression.

Others

IIf (condition, value if true, value if false) - Returns whatever value is placed in Value if true if condition is true or whatever is in Value if false if conditon is false. In this case condition is the value you are testing. e.g. IIf(NumberField=0, "no value", NumberField)

IsNull(expression) - Returns true if the expression evaluates to Null and false if it doesn't.

Nz (variant, [value if null]) - Returns the value if null whenever the variant has a null value. The default for value if null is an empty string. Although this specifies a variant it will accept a value of any datatype and treat it as a variant.
Nov 27 '07 #1
1 19360
Coni
14
Thank you for posting these useful functions.
Sep 7 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: sss | last post by:
Hello All, I am currently creating a browser interface for our thick client which was built on Visual Basic using COM ( a three tier environment). We support environments where the SQL...
1
by: acrocker | last post by:
I would like to provide access to users who need to be taken directly to the relevant page without further navigation instructions. Unfortunately the page I want to access is built using a...
9
by: Alan Lane | last post by:
Hello world: Background: Yesterday, January 21, Doug Steele was kind enough to help me out on a Left Join problem. I was trying to return all stores and their Gross Adds for December, 2004...
16
by: MLH | last post by:
I have created an A97 runtime distribution for the first time in my life this morning. I had precious little time to do it and was unable to create the distributable installation fileset with the...
43
by: sinister | last post by:
Is MS Access a true RDBMS?
2
by: richp | last post by:
I recently built an Access 2003 database on my workstation. I have a client .mdb file with my forms/code, which links tables from an .mdb on our server. When I copy the client .mdb to a user's...
48
by: meyer | last post by:
Hi everyone, which compiler will Python 2.5 on Windows (Intel) be built with? I notice that Python 2.4 apparently has been built with the VS2003 toolkit compiler, and I read a post from Scott...
1
by: brownr9 | last post by:
Hello, We're new to Access 2003 programming, and we are developing a database for our church. We built the database from the IMPORT of a Excel spreadsheet. Now we are trying to write a FORM...
1
by: anthony.k.farrant | last post by:
Hello everybody, I am new to Access. I have to rewrite an app built with Access upon SQL Server. Access links to SQL Server with linked tables. Now i'd like to change the connection properties...
1
by: rrrelic | last post by:
Can someone help me with this? I am running Access 2003 and attempting to import and append multiple XML files into Access. I currently do this process using the Import tool built into Access’s...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.