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

Form Recordset in Access 2007 Returning no data
MS Access MSChart.Graph.8 not printing
Export MS Access Memo field and convert Unicode
Using function from form in Access SQL statement?
How to update an access field w/the date everytime a change is made to its row?
Is Access's AutoNumber (Increment) guaranteed to increment?
VBA Code to Count all Columns that are numeric in ListBox containing SQL Query Results
How to requery a subform from another form?
Is it possible to create a recursive query in Access?
MS Access 2000 Report needs to be PDF format with URL hyperlinks
Deploying Access as a client-server application
Resize form based on if subform visible
MS Access search for record by textbox instead of dropdown
Uniqueness Constraints in MS Access
Application Icon path in MS Access
Microsoft access is a mere file or data-base server

Categories

HOME
jdo
proxy
gremlin
server
drivers
dictionary
kde
hp-exstream
session
vmware
amortized-analysis
rubygems
fingerprint
ojdbc
azure-storage-tables
windows-10-universal
modelica
google-cloud-ml
google-cloud-spanner
dynamics-crm-online
netflix
django-simple-history
systemc
seaborn
database-replication
sms-gateway
google-cloud-speech
jprofiler
tokenize
tapestry
zurb-foundation-6
dxf
fish
fopen
social-media
ping
saas
dbclient
windowbuilder
vision
bcd
exuberant-ctags
jspresso
catch-all
cloud-code
amazon-kinesis-kpl
espeak
dynamics-crm-2013
leading-zero
midl
sas-jmp
termination
knockout-components
snmptrapd
akka-cluster
cudafy.net
dynamics-sl
android-fonts
adxstudio-portals
underscore.js-templating
mathematica-frontend
gridview-sorting
react-native-listview
ubuntu-10.04
python-stackless
packagist
whois
dlna
livequery
ipconfig
uid
vhd
srand
separator
maven-tomcat-plugin
lib.web.mvc
t4mvc
fouc
coveralls
ideamart
c++03
npapi
googlemock
bitcoinj
zend-route
aapt
p4java
jubula
poller
app42
spring-io
dotnetnuke-5
flash-builder4.5
eventual-consistency
rabl
coderush
google-email-migration
ticoredatasync
bubble-chart
osql
spring-portlet-mvc
semantic-diff
bigcouch
winbugs14
fluent-interface
zend-translate
suppress

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
Mobile App
Mobile App
Mobile App