MS Access: And Function
This MSAccess tutorial explains how to use the Access And function with syntax and examples.
Description
The Microsoft Access And function returns TRUE if all conditions are TRUE. It returns FALSE if any of the conditions are FALSE.
Syntax
The syntax for the And function in MS Access is:
condition1 And condition2 [... And condition_n] )
Parameters or Arguments
- condition1, condition2, ... condition_n
- Expressions that you want to test that can either be TRUE or FALSE.
Returns
The And function returns TRUE if all conditions are TRUE.
The And function returns FALSE if any of the conditions are FALSE.
Applies To
The And function can be used in the following versions of Microsoft Access:
- Access 2019, Access 2016, Access 2013, Access 2010, Access 2007, Access 2003, Access XP, Access 2000
Example in VBA Code
The And function with this syntax can only be used in VBA code in Microsoft Access.
Let's look at an example that combines the And function with the If Statement in VBA:
If LWebsite = "TechOnTheNet.com" And LCount > 250 Then LResult = "High" Else LResult = "Low" End If
This would set the LResult variable to the string value "High" if both LWebsite was "TechOnTheNet.com" and LCount > 250. Otherwise, it would set the LResult variable to the string value "Low".
You can use the And function with the Or function in VBA, for example:
If (LWebsite = "TechOnTheNet.com" Or LWebsite = "CheckYourMath.com") And LCount >=1000 Then LTotal = 5 Else LTotal = 25 End If
This would set the LTotal variable to the value 5 if LWebsite was either "TechOnTheNet.com" or "CheckYourMath.com" and LCount >=1000. Otherwise, it would set the LTotal variable to the value 25.
Advertisements