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

accessing report check box in module (ms access)
Connecting VB6 and MS Access 2007
how to autoincrement the default value in texbox
Adding logic to a sub form in Access?
how to display specific records for editing in MS Access
creating more forms after exporting MS Access database
ms access - return records from sql Stored procedure
How to check if .Attachment.Add “filename” is successful before send
Access 2003 Select records with null time
Access: Shell cmd Open MDB
Append Records From Passthrough Query to Local Table
MS-Access library for performing many kinds of DDL operations on a database (to facilitate application version upgrades)?
How to Remove Stop Words from a string using Visual Basic?
Microsoft Access runtime error 2455 when trying to access grandchildren forms from child form
Microsoft Access - stored procedure with cursor
MS Access - Write to Table Immediately After Changing Value in Form

Categories

HOME
winforms
include
bpmn
mean-stack
adb
programming-languages
twitter-bootstrap-4
qore
portia
amazon-cloudformation
maude-system
rascal
mapserver
qt-creator
nstableview
jplayer
alignment
messages
telephony
flux
telerik-reporting
restful-authentication
android-widget
sparse-matrix
fluentvalidation
maquette
elasticsearch-ruby
log4js-node
gitignore
srcset
nat
junit5
mozilla
rotational-matrices
multilingual
opshub
greenrobot-eventbus
trim
sql-server-agent
http-live-streaming
businessworks
skeleton-css-boilerplate
flickr-api
filepicker
upstart
zip4j
datastax-startup
fancybox-2
rdfs
statsd
slickedit
sqlbulkcopy
nbconvert
hittest
sonarlint-vs
account-kit
or-tools
google-feed-api
ctest
merge-conflict-resolution
pagedlist
sigabrt
actionbardrawertoggle
hover-over
php-parse-error
goose
cloudbees
natvis
ios8-today-widget
r-tree
reactive-banana
cyclomatic-complexity
streambase
facebook-graph-api-v2.4
fscommand
sorl-thumbnail
block-device
network-interface
relocation
preferences
rdl
bitcoinj
has-many-through
doskey
ember-charts
floating-point-precision
jsctypes
access-rights
listings
odata4j
bluepill
multipage
bubble-chart
gwt-ext
stage
coredump
invite
krl
mozilla-prism
swing-app-framework
pascal-fc
zune
signal-handling

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