I tried using DLast function but its not working below is the code: - Me.txtReturnedYear = Nz(DLast("returnedYear", "documentLog", "fileCode LIKE '" & Me.txtFileCode & "*'"), "")
as I understood, DLast function takes the last record of the table.
17 6274
Starting with the criteria section of the DLast function, make it be - "FileCode LIKE '" & Me.txtFileCode & "' & *"
will it be like this sir? - Me.txtReturnedYear = Nz(DLast("fileCode LIKE '" & Me.txtFileCode & "*'", "returnedYear", "documentLog", ), "")
You were closer your first try. Try this - Me.txtReturnedYear = Nz(DLast("returnedYear", "documentLog", "FileCode LIKE '" & Me.txtFileCode & "' & *"), "")
sir, I got an error ... SYNTAX ERROR (MISSING OPERATOR) IN QUERY EXPRESSION 'fileCode LIKE 'me.txtFileCode(value)'&*'
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.
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: - Dim strCriteria as String
-
strCriteria = "FileCode LIKE '" & Me.txtFileCode & "' & *"
-
MsgBox strCriteria
-
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.
I will admit that I have never understood why they choose that name for the function. It does seem quite mis-leading.
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. - Me.txtReturnedYear = Nz(DLast("returnedYear", "???", "fileCode LIKE '" & Me.txtFileCode & "*'"), "")
is the correct format for the call.
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 =)
@seth, it gave me same error as the previous one ....
@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 - Dim logNo As String
-
Dim user As String
-
Dim fileNo As String
-
Set db = CurrentDb
-
Set rst = db.OpenRecordset("mainTableArchive", dbOpenTable)
-
-
rst.Index = "Primarykey"
-
rst.Seek "=", Me.txtFileCode
-
-
If rst.NoMatch Then
-
MsgBox "Record not Found!"
-
-
Me.txtFileCode.Value = ""
-
Me.txtDocType.Value = ""
-
Me.txtDocNo.Value = ""
-
Me.txtDocTitle.Value = ""
-
Me.txtAssetNo.Value = ""
-
Me.txtEquipType.Value = ""
-
Me.txtEquipModel.Value = ""
-
Me.txtAssetOwner.Value = ""
-
-
Me.txtFileCode.SetFocus
-
Else
-
'returns value to txtReturnedYear
-
Me.txtReturnedYear = Nz(DLast("returnedYear", "documentLog", "fileCode LIKE '" & Me.txtFileCode & "*'"), "")
-
'returns value to string fileNo
-
fileNo = Nz(DLast("fileCode", "documentLog", "fileCode LIKE '" & Me.txtFileCode & "*'"), "")
-
'returns value to string LogNo
-
logNo = Nz(DLast("docLogNo", "documentLog", "fileCode LIKE '" & Me.txtFileCode & "*'"), "")
-
If Me.txtReturnedYear = "" And Me.txtFileCode = fileNo Then
-
user = Nz(DLast("fullName", "documentLog", "fileCode LIKE '" & Me.txtFileCode & "*'"), "")
-
MsgBox "File was taken out by " & user
-
Me.txtFileCode.SetFocus
-
Me.txtFileCode.Value = ""
-
Me.txtDocType.Value = ""
-
Me.txtDocNo.Value = ""
-
Me.txtDocTitle.Value = ""
-
Me.txtAssetNo.Value = ""
-
Me.txtEquipType.Value = ""
-
Me.txtEquipModel.Value = ""
-
Me.txtAssetOwner.Value = ""
-
Else
-
Me.txtDocType = rst.docType
-
Me.txtDocNo = rst.docNo
-
Me.txtDocTitle = rst.docTitle
-
Me.txtAssetNo = rst.assetNo
-
Me.txtEquipType = rst.equipType
-
Me.txtEquipModel = rst.equipModel
-
Me.txtAssetOwner = rst.assetOwner
-
-
Me.cmbTakeOutDay.SetFocus
-
Me.txtReturnedYear.Value = ""
-
End If
-
End If
-
rst.Close
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.
@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 ...
now it's ok, I used DMax on PK and everything is fine... thanks for all your suggestions and replies ... @seth and @neopa..
NeoPa 32,556
Expert Mod 16PB
Glad you managed to find a solution anyway :-)
yes ... thank you sir neopa ...
Sign in to post your reply or Sign up for a free account.
Similar topics
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) {...
|
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...
|
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">...
|
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="";...
|
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...
|
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...
|
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.....
|
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...
|
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...
|
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...
|
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...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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...
| |