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 "))
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?