ms-access


Calendar query from table [duplicate]


MS Access 2003.
I need to get the array of dates which are located in the range start_date to end_date.
I not found such function in standard set of MS Access.
I write VBA function:
Option Compare Database
' © Andrey Bushman, 2014
' Get the array of dates which are located in the range start_date to end_date.
' The result is an array of Date items.
Public Function GetDays(start_date As Date, end_date As Date)
If start_date > end_date Then
' end_date can't be less than start_date.
GetDays = Null
Exit Function
End If
Dim size As Long
size = end_date - start_date
Dim result() As Date
ReDim result(size) ' including the range boundaries.
Dim index As Long
index = 0
Dim day As Date
day = start_date
Do While day <= end_date
result(index) = day
day = day + 1
index = index + 1
Loop
GetDays = result
End Function
My SQL query:
SELECT tbChecks.CheckId, tbChecks.[In], tbChecks.Back, GetDays([In],[Back]) AS DayItem FROM tbChecks;
But I get an #Error text in the DayItem field for each record.
This is not work too:
SELECT GetDays(CDate("01.01.2014"), CDate("05.01.2014")) as DayItem;
I get the error: Data type mismatch in criteria expression. (Error 3464).
How can I solve it?
You are getting errors because your VBA function is returning an array of Date values but the Access Database Engine does not have an Array field type. Even if it did, you would wind up with a single row containing an array of dates and (according to the comments to the question) you want each date in a separate row.
You should be able to accomplish your goal without using VBA at all if you create a "Numbers" table with sequential integer values from 0 to a sufficiently large value, e.g.,
n
----
0
1
2
3
...
998
999
1000
and then use a query like this:
SELECT DateAdd("d",n,#2014-01-01#) AS DayItem
FROM Numbers
WHERE n <= DateDiff("d",#2014-01-01#,#2014-01-05#)
returning
DayItem
----------
2014-01-01
2014-01-02
2014-01-03
2014-01-04
2014-01-05

Related Links

increase speed of access database on network drive
Access VBA variables don't seem to clear after sub routine, getting procedure declaration does not match
How to stop auto open pdf from Microsoft Access when export data
ms-Access combo box query
How to make MS Access run a query on focus lose event and take actions accordingly
Access Report: Sum up the two formula text boxes in a new text box
Access 2007: How to do weekstart and weekending and have the weekending dates show on result
Why did conditional formatting stop working?
How to Auto fill field from another Table in Access 2007 Depend on previous filled
Handling null date values in Access queries
How to copy a table's contents from an Access 97 file into an Access 2013 file
Open Report based on text field
calculated field combining multiple fields into one
what is a meaning of message “invalid argument to function ms access”
Group records and put into different tables in access
Searching Sharepoint/Access - Update table

Categories

HOME
java
openlayers
tizen
cvs
rdf
packages
jpeg
baqend
ezpublish
mouse
autotools
android-youtube-api
google-translate
adobe-analytics
quartz-scheduler
google-static-maps
propel
evopdf
oxyplot
functional-testing
php-openssl
p-value
javacv
wpfdatagrid
internet-explorer-9
linkerd
dbclient
r-raster
siesta-swift
caret
cloud-code
jmonkeyengine
vxworks
restlet
retina-display
hockeyapp
sharefile
hue
streamreader
cookiecutter-django
optix
gulp-sourcemaps
mime
darcs
worker-thread
feeds
dynamics-sl
chord-diagram
yt-project
ado.net-entity-data-model
impresspages
autorest
rvest
fadeout
hexdump
rhino-servicebus
jfugue
rtbkit
srand
wso2cloud
sdhc
t4mvc
libressl
proj4js
inmobi
nsmutabledictionary
gwidgets
phalanger
rdtsc
java-metro-framework
reactfx
doskey
mysql-error-1062
mechanize-ruby
bundles
ember-charts
meteor-velocity
access-rights
flash-builder4.5
batterylevel
eclipse-memory-analyzer
plasma
android-screen-support
delphi-6
gil
automount
jquery-ui-layout
spring-portlet-mvc
whoosh
gnu-prolog
doh
xmlspy
cinema-4d
recent-documents
calling-convention
disclosure
database-management
zend-tool
kdbg
libs
exchange-server-2003
aquaticprime
genealogy
rtml
document-conversion

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile