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

EasyPHP connecting to MS Access
Access 2010 Runtime question
Access Input textbox on Data Access page with only select enabled to allow filter by searchs
Microsoft Access Query through VBA gets repeated?
What sort of functionality can I expect from exporting a Microsoft Access 2007 Database to a WSS 3.0 site?
query muliple fields with multiple values
Force OpenCurrentDatabase to use Access 2003
ACCESS/VBA: How to create a ON/OFF type switch to allow record modification on a form?
dsn for ms access 2003 in windows 7
How can I find all the MS Access security groups in VBA
Dropdownmenu's linked?
Drop all connection to MS Access Database using ADO.NET
Import MS Access to CSV on Mac programmatically
MS Access - Is there a limit to Public Functions/Routines in MS Access? RTE #7?
Need to Allow Null or “” values for Dates - Access Query Data type mismatch
How to migrate MS access database to Oracle?

Categories

HOME
winforms
omnet++
relay
survey
sql-server-2016
yum
indesign
qore
slurm
primary-key
event-handling
quickfix
try-catch
tostring
invantive-sql
pythonanywhere
normalizr
jqwidget
contextmenu
scichart
custom-wordpress-pages
xlsxwriter
riot.js
abi
sox
jndi
qhull
greendao
maquette
kendo-datasource
nameservers
functor
catch-all
phpfreechat
azure-sql-database
accelerate-framework
cloud-code
code-search-engine
hilbert-curve
webix-treetable
angularjs-factory
particles.js
preconditions
mapzen
quadratic-programming
eclipse-gef
btrace
dotcover
scrollable
hibernate-tools
promela
mplayer
composite-key
ifs
dynamics-sl
orthogonal
heidisql
radtreelist
py2app
autorest
bstr
multiple-regression
qgraphicsview
whois
dataview
rhino-servicebus
goose
itextpdf
feedback
citrus-pay
dereference
directoryservices
codeigniter-url
cdt
javafx-webengine
code-access-security
project-planning
mesa
quantlib-swig
dir
apc
mylyn
ocunit
windows-phone-7.1.1
custom-backend
eclipse-templates
data-loss
external-accessory
mod-auth
file-comparison
gamequery
icanhaz.js
firefox-5
data-driven
defensive-programming
w3wp
msdev
lzh

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