ms-access


MS Access - Dlookup to set value of field based on content of another table


I'm a newbie to Access.
I have two tables.
The first is called Dates - it has 3 columns (apart from the key) which are:
From Date (e.g. 01/07/2017)
To Date (e.g. 30/09/2017)
Period (e.g. 2017-2018 Q1)
The second table is called Expenses, and it has many columns, two of which are Expense Date and Period.
Expense Date is input by the user.
I want Period to be filled via a DLookup function from the Dates table based on the Expense Date, e.g. (using Excel syntax)
`DLOOKUP(["From Date":"To Date","Expense Date","Period")`
I am assuming this function would need to be written in Row Source under the Lookup tab of the Expenses design view.
Would anyone be able to tell me what is the correct syntax for Access and where I should write the required function?
If you have a form bound to table Expenses, you would use the AfterUpdate event of the textbox bound to field Expense Date (here named TextExpenseDate):
Private Sub TextExpenseDate_AfterUpdate()
If IsNull(Me!TextExpenseDate.Value) Then
Me!Period.Value = Null
Else
Me!Period.Value = DLookup("Period", "Dates", "#" & Format(Me!TextExpenseDate.Value, "yyyy\/mm\/dd") & "# Between [From Date] And [To Date]")
End If
End Sub
No, you would not use a DLookup in the RowSource. You would use an SQL statement.
A DLookup() expression can be used in the ControlSource property of a textbox or in Field cell of query design view.
In this case the expression would be:
DLookup("Period", "Dates", "#" & [Expense Date] & "# BETWEEN [From Date] AND [To Date]")
If you are using international dates, review http://allenbrowne.com/ser-36.html. Gustav's suggestion for formatting the data may be needed.
Refer to Access Help or Google search to learn more about domain aggregate functions.
Advise no spaces nor punctuation/special characters (underscore only exception) in names.

Related Links

Creating a quick entry feature in Microsoft Access
Form Customization without VBA
selstart returns position 0 if text is entered in memo field (not clicked)
Microsoft Access 2010 (mdb) automation with user based security
Dropdown list - default value
Share Windows folder outside my local network
VBA Access - Multiple Tables count by date
MS Access Pop-up on table modification
Combining multiple queries in one in Access
Fill table with all month days
Form based on a one-to-many relationship - just show parent records with child actions
Select Max Date by Date Range
MS Access Implementing FULL OUTER JOIN via UNION operator with AGGREGATION
access DLookUp multiple criteria
Combining 3 strings in Access VBA
DoCmd.TransferSpreadsheet triggering Error 3275 “unexpected error from external database driver”

Categories

HOME
compiler-construction
ionic-framework
image-processing
azure-data-factory
single-sign-on
kde
plone
vmware
alfresco
sharepoint-designer
google-project-tango
alpha
uber-api
ios-charts
gitpitch
python-unittest
user-input
qt-creator
correlation
google-apps-marketplace
google-cloud-ml
windows-azure-storage
alignment
commonmark
hex-editors
event-handling
progressive-web-apps
pythonanywhere
beyondcompare
openedx
google-pagespeed
immutable.js
cloudhub
telerik-reporting
bootstrap-tour
devops
wijmo
hammerspoon
maxmind
spring-mybatis
c++-amp
lightswitch-2013
react-chartjs
asset-pipeline
android-kernel
wallpaper
picasso
neuroscience
sharefile
impersonation
splice
ws-security
heightmap
qwt
chain-builder
strptime
dotnetzip
svmlight
imanage
titanium-android
probability-density
sts-springsourcetoolsuite
underscore.js-templating
py2app
t4mvc
atk4
ideamart
composite
jsapi
geonetwork
website-monitoring
block-device
clicktag
dd
internet-connection
code-access-security
didselectrowatindexpath
typo3-neos
soundtouch
flash-builder4.5
spring-validator
drools-planner
ocunit
selected
quickdialog
automount
objective-c-2.0
ocx
postgresql-performance
spyware
subgurim-maps
genshi
psi
swing-app-framework
genealogy

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html