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

MS Access 2013 Visibility Issues
Print subform results
getting the value of two fields with checkbox
Is it possible to bind form controls to VBA properties?
SQL Query to retrieve Item name and sum of amounts for that item
Query missing data from select fields for only 2 records
Microsoft Access - Search Query
Like with IIF and date range not returning results
OPening multiple copies of ACCESS app
Access New ID Field YYYYMMNN [duplicate]
Sequential Number Column with YYYYMM
I am trying to get the correct font size for my subform in Access
Start and stop MS Access VBA code on a specific time
Table Joining (ms Access, sql)
Howto write DDL ALTER TABLE Modify statement using string variable for TABLE name
Filter combobox: how to add “NOT filtered” option?

Categories

HOME
cakephp
openlayers
vbscript
json.net
onedrive
at-command
jpeg
webpack-2
swagger-ui
synchronization
volttron
nstableview
usergrid
solaris-10
reactive-cocoa
textfield
ehcache
sox
google-search-api
extjs5
realex-payments-api
blazemeter
android-widget
xpages-ssjs
buildbot
intel-pin
strncpy
xacml
ejabberd-module
jspm
libuv
skia
fabric8
create-table
catel
azure-sql-database
mmenu
overlap
simplexml
git-merge
event-driven
eclipse-scout
arena-simulation
checkboxlist
wptoolkit
logfiles
komodoedit
pebble-watch
dropbox-php
capacity
crosswalk-runtime
xcb
underscore.js-templating
connect-by
skype4py
qcustomplot
superstack
bgp
dlna
rhino-servicebus
javax.sound.midi
ionic
skos
e10s
fscommand
javafx-webengine
php-5.4
castle
fluentautomation
poller
meteor-velocity
srs
openlaszlo
ivyde
spring-io
mylyn
android-screen-support
pvrtc
coderush
bluepill
manchester-syntax
chrono
removeclass
asyncfileupload
imac
lang
gamma
routedevent
ext3
bespin
brewmp
sef
exchange-server-2003
uimenucontroller
noscript
project-hosting
defensive-programming
3gp





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