My dlookup is returning a 0 when it should return a value of 935. I have double check the spelling of the variable and tables. I can't seem to figure out where I'm going wrong on this on. - [Punch ID] = Nz(DLookup("[Punch ID]", "[Copy of Employee Work Statistics1]", "Employee='" & Forms![Royal time Stamp]![Driver] & "' And [Date]=#" & Date & "#" & " And [Trip Sign Off]=0"), 0)
Thanks for your help,
Vasago
Since you are doing so many DLookups on the same table, you would probably increase performance if you just opened the recordset and used the values from that. All the domain functions (those that start with D; DLookup, DCount, DSum, etc.) are very resource intensive and therefore slow down your code. You can open your recordset like this: - Dim db as DAO.Database
-
Dim rst As DAO.Recordset
-
Dim strRst as String
-
-
Set db = CurrentDb
-
strRst = "SELECT [Punch ID] " & _
-
"FROM [Copy of Employee Work Statistics1] " & strCriteria
-
Set rst = db.OpenRecordset(strRst, dbOpenDynaset)
-
-
'you can reference your values like this
-
[Punch ID] = rst![Punch ID]
-
-
-
'At the end of your code, close what you open
-
'and release what you set
-
rst.close
-
set db = nothing
-
set rst = nothing
10 3233
I did have one after thought. Could it be because my tables date also has the time stamp attached to the date and how would I add in a format dates to "short date" into the dlookup
First, lets start by splitting out your criteria into its own string so that we can debug your code. - dim strCriteria as string
-
strCriteria = "Employee='" & Forms![Royal time Stamp]![Driver] & "' And [Date]=#" & Date & "# And [Trip Sign Off]=0"
-
debug.print strCriteria
-
-
[Punch ID] = Nz(DLookup("Punch ID", "Copy of Employee Work Statistics1", strCriteria), 0)
The fact that it is returning 0 and that you are using the Nz() function with 0 as the return value makes me think that your DLookup() was returning a null value. Try my code, run it and the post back what gets entered into the immediate window (Ctrl + g to view it). It is possible that the square brackets were also causing the problem, but I'm not positive of that.
Here is what was in the immediate window.
"Employee='Batson, Leroy' And [Date]=#4/7/2014# And [Trip Sign Off]=0"
My [Date] field that it is looking up is formatted to a Medium Date. Would that cause issues with the dlookup using the current date?
Access is usually pretty good about comparing dates since it is actually comparing the date value (an integer) not the format of the date. It is a bad idea to use reserved words as field names (such as Date). Even when put in brackets, it can sometimes cause problems.
Can you verify the data types of the Employee and [Trip Sign Off] fields that Employee is a text data type and [Trip Sign Off] is a number or yes/no field?
Try creating a query such as the following and see what errors you get or what the results are. - SELECT [Punch ID]
-
FROM [Copy of Employee Work Statistics1]
-
WHERE Employee='Batson, Leroy'
-
And [Date]=#4/7/2014#
-
And [Trip Sign Off]=0
[Trip Sign Off] Data Type = Date/Time (formatted as short time)
[Employee] Data Type = Short Text
Creating the query listed above outputs the value I am looking for in the Dlookup.
Here is all the code on the Form Load. Just in case this help out at all. - Private Sub Form_Load()
-
Dim strCriteria As String
-
-
strCriteria = "Employee='" & Forms![Royal time Stamp]![Driver] & "' And [Date]=#" & Date & "# And [Trip Sign Off]=0"
-
-
Debug.Print strCriteria
-
-
[Punch ID] = Nz(DLookup("Punch ID", "Copy of Employee Work Statistics1", strCriteria), 0)
-
-
[Type of Work] = Nz(DLookup("[Type of Work]", "[Copy of Employee Work Statistics1]", strCriteria), 0)
-
If [Type of Work] = "" Then
-
-
Else
-
Me.[Type of Work].Locked = True
-
[Trip_S_on] = Nz(DLookup("[Trip Sign On]", "[Copy of Employee Work Statistics1]", strCriteria), 0)
-
If [Type of Work] = "Transportation Specialist" Then
-
Me.[bus number].Visible = True
-
[bus number] = Nz(DLookup("[Bus Number]", "[Copy of Employee Work Statistics1]", strCriteria), 0)
-
Me.[bus number].Locked = True
-
-
Me.Route.Visible = True
-
[Route] = Nz(DLookup("[Route]", "[Copy of Employee Work Statistics1]", strCriteria), 0)
-
Me.Route.Locked = True
-
Else
-
Me.Route.Locked = False
-
Me.School.Locked = False
-
Me.[bus number].Locked = False
-
End If
-
If [Route] = "field Trip" Then
-
Me.[School].Visible = True
-
[School] = Nz(DLookup("[School]", "[Copy of Employee Work Statistics1]", strCriteria), 0)
-
Me.School.Locked = True
-
Else
-
Me.School.Locked = False
-
End If
-
End If
-
-
End Sub
And you are still getting 0 (a wrong value) when using the dlookup()? Hmmm... Try this - dim strCriteria as string
-
strCriteria = "Employee='" & Forms![Royal time Stamp]![Driver] & "' And [Date]=#" & Date & "# And [Trip Sign Off]=0"
-
debug.print strCriteria
-
debug.print DLookup("Punch ID", "Copy of EmployeeWork Statistics1", strCriteria)
-
-
[Punch ID] = Nz(DLookup("Punch ID", "Copy of Employee Work Statistics1", strCriteria), 0)
Since you are doing so many DLookups on the same table, you would probably increase performance if you just opened the recordset and used the values from that. All the domain functions (those that start with D; DLookup, DCount, DSum, etc.) are very resource intensive and therefore slow down your code. You can open your recordset like this: - Dim db as DAO.Database
-
Dim rst As DAO.Recordset
-
Dim strRst as String
-
-
Set db = CurrentDb
-
strRst = "SELECT [Punch ID] " & _
-
"FROM [Copy of Employee Work Statistics1] " & strCriteria
-
Set rst = db.OpenRecordset(strRst, dbOpenDynaset)
-
-
'you can reference your values like this
-
[Punch ID] = rst![Punch ID]
-
-
-
'At the end of your code, close what you open
-
'and release what you set
-
rst.close
-
set db = nothing
-
set rst = nothing
Seth,
I can't thank you enough for your help and for the "access VBA Class".
Sincerely,
Vasago
Sign in to post your reply or Sign up for a free account.
Similar topics
by: mjm |
last post by:
Folks,
Stroustrup indicates that returning by value can be faster than
returning by reference but gives no details as to the size of the
returned object up to which this holds.
My question is...
|
by: Phoenix |
last post by:
I am trying to print date headings over comments (as headings)
I have a simple XML file :
<comments>
<comment id=1234 yyyymmdd="20041230" flag="Y">..text..</comment>
<comment id=1309...
|
by: Epson Barnett |
last post by:
I have a C# Web application I'm working on that loads a csv file on
application start. The csv is an inventory file which is used to
create a collection in the Application object. If the collection...
|
by: JKop |
last post by:
AnyClass Blah()
{
AnyClass poo;
return poo;
}
As we all know, in the above, the compiler is entitled to:
|
by: Roy Gourgi |
last post by:
Hi,
I would like to able to able to return a value from a called function but
also retain the loop counter in the called function the next time I call it
again.
TIA
Roy
|
by: Earl T |
last post by:
When I try to get the netscape version for version 7, I get the
HttpBrowserCapabilities class returning the version as 5 and not 7.
(see code and output below)
CODE
HttpBrowserCapabilities...
|
by: Nathan Sokalski |
last post by:
I have a DropDownList that is returning the value from index 0 regardless of
which item is selected. The code that I am using to test which index it is
returning is:
Label1.Text =...
|
by: Parul Bagadia |
last post by:
I m returning a value of pointer of a structure from one function to main; but whenever it comes in main it becomes NULL... i used another pointer in main and equated its value to returning pointer...
|
by: Ryan Le Piane |
last post by:
Hi everyone,
I am trying to program a Form Pay Estimator and it calculates the gross pay, taxes owed, and net pay for an individual employee. For some reason my CalculateTaxes method in my Pay()...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |