473,394 Members | 1,951 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

DLast function not working

82 64KB
I tried using DLast function but its not working below is the code:

Expand|Select|Wrap|Line Numbers
  1. Me.txtReturnedYear = Nz(DLast("returnedYear", "documentLog", "fileCode LIKE '" & Me.txtFileCode & "*'"), "")
as I understood, DLast function takes the last record of the table.
Apr 5 '13 #1
17 6274
Seth Schrock
2,965 Expert 2GB
Starting with the criteria section of the DLast function, make it be
Expand|Select|Wrap|Line Numbers
  1. "FileCode LIKE '" & Me.txtFileCode & "' & *"
Apr 5 '13 #2
deanvilar
82 64KB
will it be like this sir?

Expand|Select|Wrap|Line Numbers
  1. Me.txtReturnedYear = Nz(DLast("fileCode LIKE '" & Me.txtFileCode & "*'", "returnedYear", "documentLog", ), "")
Apr 5 '13 #3
Seth Schrock
2,965 Expert 2GB
You were closer your first try. Try this
Expand|Select|Wrap|Line Numbers
  1. Me.txtReturnedYear = Nz(DLast("returnedYear", "documentLog", "FileCode LIKE '" & Me.txtFileCode & "' & *"), "")
Apr 5 '13 #4
deanvilar
82 64KB
ok sir i will try now.
Apr 5 '13 #5
deanvilar
82 64KB
sir, I got an error ... SYNTAX ERROR (MISSING OPERATOR) IN QUERY EXPRESSION 'fileCode LIKE 'me.txtFileCode(value)'&*'
Apr 5 '13 #6
TheSmileyCoder
2,322 Expert Mod 2GB
Hi Deanvilar and welcome to Bytes.
A few pointers which might be helpful in the future.

"Not working" is actually not a great way to describe a problem, since "Not working" can actually cover a whole lot of scenarios. You need to be more specific, such as "This causes an error 9 and the error message is "Index out of bounds"

Or the code is running, but I am not getting the results I expected, or nothing seems to be happening at all. Trust me when I state that time you spend on making a good question comes back in time saved on answering followup-questions.


Now, you seem to have it wrong, in believing that Dlast will always return the last record. It is however a quite common mis-conception. It will often return the last record, but that cannot be guaranteed. In fact the Access help on Dlast states:
Access 2010 help on Dlast
You can use the DLast function to return a random record from a particular field in a table or query when you simply need any value from that field.
And a bit furhter down it also states:
Access 2010 help on Dlast
If you want to return the first or last record in a set of records (a domain (domain: A set of records that is defined by a table, a query, or an SQL expression. Domain aggregate functions return statistical information about a specific domain or set of records.)), you should create a query sorted as either ascending or descending and set the TopValues property to 1. From Visual Basic, you can also create an ADO Recordset object and use the MoveFirst or MoveLast method to return the first or last record in a set of records.
Apr 5 '13 #7
Seth Schrock
2,965 Expert 2GB
Thanks for that Smiley. I had never heard of the DLast function until I looked up this question and was just going off the syntax, not what the function actually did.

@deanvilar Lets try this:
Expand|Select|Wrap|Line Numbers
  1. Dim strCriteria as String
  2. strCriteria = "FileCode LIKE '" & Me.txtFileCode & "' & *"
  3. MsgBox strCriteria
  4. Me.txtReturnedYear = Nz(DLast("returnedYear", "documentLog", strCriteria), "")
Please post what the message box displays without any additional quotes or changes of values. This will allow us to see what the database engine is working with.
Apr 5 '13 #8
TheSmileyCoder
2,322 Expert Mod 2GB
I will admit that I have never understood why they choose that name for the function. It does seem quite mis-leading.
Apr 5 '13 #9
NeoPa
32,556 Expert Mod 16PB
I'm afraid Seth's advice on this occasion is not correct. In fact your first code was more correct.

However, 'Last' as a concept only makes sense when you properly understand that a table holds a set of records, and not a set of records in any particular order. There may be a default order but you need to understand what that is before relying on it. Alternatively, work from a recordset where the order is specific.

Expand|Select|Wrap|Line Numbers
  1. Me.txtReturnedYear = Nz(DLast("returnedYear", "???", "fileCode LIKE '" & Me.txtFileCode & "*'"), "")
is the correct format for the call.
Apr 6 '13 #10
deanvilar
82 64KB
sir Smiley sorry for not providing specific problem of the code, anyway it's working but as they told the sense of returning the last record of DLAST is not giving me the proper results I need ... next time I would specify each detail of the problem .... thanks for the reply sir ....

@seth and @neopa am going to try your codes now ... i hope it'll solve my problem =)
Apr 6 '13 #11
deanvilar
82 64KB
@seth, it gave me same error as the previous one ....
Apr 6 '13 #12
deanvilar
82 64KB
@neopa, thanks for the advice ... am using the DLAST function to check another table as I already have a recordset to check a table for other records ... sir @seth and @neopa here is my
code
Expand|Select|Wrap|Line Numbers
  1. Dim logNo As String
  2. Dim user As String
  3. Dim fileNo As String
  4. Set db = CurrentDb
  5. Set rst = db.OpenRecordset("mainTableArchive", dbOpenTable)
  6.  
  7. rst.Index = "Primarykey"
  8. rst.Seek "=", Me.txtFileCode
  9.  
  10. If rst.NoMatch Then
  11.     MsgBox "Record not Found!"
  12.  
  13.     Me.txtFileCode.Value = ""
  14.     Me.txtDocType.Value = ""
  15.     Me.txtDocNo.Value = ""
  16.     Me.txtDocTitle.Value = ""
  17.     Me.txtAssetNo.Value = ""
  18.     Me.txtEquipType.Value = ""
  19.     Me.txtEquipModel.Value = ""
  20.     Me.txtAssetOwner.Value = ""
  21.  
  22.     Me.txtFileCode.SetFocus
  23. Else
  24.     'returns value to txtReturnedYear
  25.     Me.txtReturnedYear = Nz(DLast("returnedYear", "documentLog", "fileCode LIKE '" & Me.txtFileCode & "*'"), "")
  26.     'returns value to string fileNo
  27.     fileNo = Nz(DLast("fileCode", "documentLog", "fileCode LIKE '" & Me.txtFileCode & "*'"), "")
  28.     'returns value to string LogNo
  29.     logNo = Nz(DLast("docLogNo", "documentLog", "fileCode LIKE '" & Me.txtFileCode & "*'"), "")
  30.         If Me.txtReturnedYear = "" And Me.txtFileCode = fileNo Then
  31.         user = Nz(DLast("fullName", "documentLog", "fileCode LIKE '" & Me.txtFileCode & "*'"), "")
  32.              MsgBox "File was taken out by " & user
  33.                 Me.txtFileCode.SetFocus
  34.                 Me.txtFileCode.Value = ""
  35.                 Me.txtDocType.Value = ""
  36.                 Me.txtDocNo.Value = ""
  37.                 Me.txtDocTitle.Value = ""
  38.                 Me.txtAssetNo.Value = ""
  39.                 Me.txtEquipType.Value = ""
  40.                 Me.txtEquipModel.Value = ""
  41.                 Me.txtAssetOwner.Value = ""
  42.         Else
  43.                 Me.txtDocType = rst.docType
  44.                 Me.txtDocNo = rst.docNo
  45.                 Me.txtDocTitle = rst.docTitle
  46.                 Me.txtAssetNo = rst.assetNo
  47.                 Me.txtEquipType = rst.equipType
  48.                 Me.txtEquipModel = rst.equipModel
  49.                 Me.txtAssetOwner = rst.assetOwner
  50.  
  51.                 Me.cmbTakeOutDay.SetFocus
  52.                 Me.txtReturnedYear.Value = ""
  53.         End If
  54.     End If
  55. rst.Close
Apr 6 '13 #13
NeoPa
32,556 Expert Mod 16PB
I hope that means you resolved your issue. Your code isn't easy to read and I don't want to go through it all just to determine if it is or not. Unless told otherwise, I'll assume it's all done.
Apr 7 '13 #14
deanvilar
82 64KB
@NeoPa, unfortunately no its not resolved yet =(

actually on the code... is to search field fileCode in table mainArchive, if found .. verify about the last record according to fileCode in table documentLog ...
Apr 8 '13 #15
deanvilar
82 64KB
now it's ok, I used DMax on PK and everything is fine... thanks for all your suggestions and replies ... @seth and @neopa..
Apr 8 '13 #16
NeoPa
32,556 Expert Mod 16PB
Glad you managed to find a solution anyway :-)
Apr 9 '13 #17
deanvilar
82 64KB
yes ... thank you sir neopa ...
Apr 9 '13 #18

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
9
by: J. Hall | last post by:
Hi guys, Witten a function to check two input boxes, ensure that only one has a numerical value in, but I'm gettng the javascript error 'Object expected'?? function...
3
by: dan_andrews | last post by:
<?xml version="1.0"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN" "http://www.w3.org/TR/MathML2/dtd/xhtml-math11-f.dtd" > <html xmlns="http://www.w3.org/1999/xhtml">...
5
by: thejes john | last post by:
could u plz help me in solving this problem.y the following is not working <script language="javascript"> function btnClear() { document.Loc_Emp.T1.value=""; document.Loc_Emp.T2.value="";...
3
by: maya | last post by:
I'm trying to chg opacity for some divs on a pg, IE is ignoring it.. (works fine in FF..) why is this.. html, css, JS code is here.. http://www.francesdelrio.com/opacity.html this is for...
3
by: triplejump24 | last post by:
Hey. Im trying to make program that basically displays all the prime numbers. I need to use bool and for but im not quite sure if i have this right. So far i have this bunch of a mess but can...
3
by: splintercell | last post by:
well i got this code from java.sun.com and tried modiifying it in all the possible ways,but to no good.. stil its not workin..pleas help me out and try postin good workinw web cralwer if u have.....
0
by: Shaikh shahnawaz | last post by:
Hi, I have implement multiple file uploading progress bar with the help of flash and .net file is upload on my local machine but not working with server it's give error while uploading image on...
1
by: rakeshy3 | last post by:
hi, i have develop a web site on cake php. on localhost it is working properly but on remote server sessions have expires from switching one function to other. can any body provide me solutins for...
16
by: tarunkhatri | last post by:
Hi. I have a javascript function to change the value of the cell on chnage event of a dropdown list.My code is workin but the problem is that the value of the cell is chaning but not respective to...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.