ms-access


Getting date from a query which is not showing exact as entered in table


I want to get MAX purchase date from a query.
I have written code which can show date in message box. But problem is that the date is not showing exactly as entered in the table. In the table date is 11-04-17, but in the message box date is shown 30-12-99.
My Code is:
Dim dbforPurdate As Database
Dim rsforPurdate As Recordset
Dim vmedid As String
Dim dtpurtbl As Date
Dim Qryfordate As String
vmedid = Me.MedID
Set dbforPurdate = CurrentDb
'Qryfordate = "SELECT Purchaset.[Purchase Date] AS PurDate, PurchaseDetailt.[Receipt No], PurchaseDetailt.MedID, PurchaseDetailt.BatchNo FROM Purchaset INNER JOIN PurchaseDetailt ON Purchaset.[Receipt No] = PurchaseDetailt.[Receipt No]"
Set rsforPurdate = dbforPurdate.OpenRecordset("Qryfordate")
dtpurtbl = Nz(DMax("[Purchase Date]", "qryfordate", [MedID] = "'" & vmedid & "'"), 0)
MsgBox Format(dtpurtbl, " dd/mm/yy ")
Your DMax() is not finding a value which returns Null and therefore the Nz() returns 0 and the Format() function converts 0 to 30-12-99.
The DMax() shows syntax errors and I am surprised you do not get runtime error. It is missing quote mark in front of [MedID] and has an extra quote mark after = sign.
Is MedID really a text type field?
DMax("[Purchase Date]", "qryfordate", "[MedID] = '" & vmedid & "'")
If you want the message box to not show the funky date value:
MsgBox IIf(dtpurtbl = 0, "No Date", Format(dtpurtbl, " dd/mm/yy "))

Related Links

MS Access: Update a Linked List Box
How can I check if an instance of a Access 2010 form is still open?
How to debug a docmd.transferdatabase statement that does not work (no compiler error, simply does not xfer the data)
How to set initial selections of controls in a MS access report on its load?
Access 2000 Timeouts on bound recordset
Query to a Meaningful Report
MS Access “duplicate values” error, but I don't know why
Generate uml from vba
Is it possible to change Msysobjects in ms access
How can I make MS-Access choose a different/the right execution plan for my query
Access 2007 Reports - How to 'unfix' fields?
Hide Access Options
MS Access “record changes” log
Format combox in Access 2007
MS Access how can a subform get the value from another subform?
Can you use ADO to edit table schema in MS Access?

Categories

HOME
sendgrid
log4j
deployment
activiti
dictionary
relative-path
tizen-web-app
enterprise-library-5
opengl-es-2.0
vault
modx-revolution
google-cloud-ml
dynamics-crm-online
designer
iolanguage
fatal-error
visual-composer
nodatime
css-animations
wkwebview
autosys
trading
dxf
qhull
publish
xacml
log4js-node
sql-server-2012-express
media-queries
copying
azure-sql-database
cloud-code
appfabric
stacked
vxworks
dism
node-gyp
menuitem
osx-mavericks
filepicker
dandelion
typed-lambda-calculus
sqlbulkcopy
epson
sqldf
specrun
firmata
ado.net-entity-data-model
django-debug-toolbar
jms2
intel-fortran
feedback
wordml
0xdbe
mono-embedding
nsight
census
dundas
graph-api-explorer
sorl-thumbnail
heisenbug
transcoding
c18
cdc
inbox
excel-2003
ora-00911
dataadapter
rabl
orchardcms-1.7
spring-validator
anonymous-methods
simba
datawindow
dotnethighcharts
cufon
work-stealing
qt-jambi
horizontal-accordion
jmock
floating
html-input
sudzc
nsviewanimation
pascal-fc
scripting-languages
geneva-server
paul-graham

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