473,662 Members | 2,666 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dlookup Function giving error in SQL String


Friends, I had posted this on "Microsoft.Publ ic.Access", But I did not
get a satisfactory response. I have been struggling for nearly 2 days
trying to crack this code. I really need help, could some one please
help me......
The Problem....

The USDollarAmt field is a calculated field, calculated
from the Original Currency Amount (OriginalCurrAm t) less the Disputed
Amount (DisputedAmtOCu r) both from the table "TblInvoiceMain " and then
multiplied with Currency Rate (Rate) that is stored in the table
"TblCurStor e", if the criteria matches the Currency (ShrtCur) {example
-'USD'} and the Period in the "TblCurStor e" to the field
"OriginalCu rr" and "FinRecdDat e" stored in the Shortdate format
{example - "21-Jan-04"} in the TblInvoiceMain. I am having problems
with this particular line below:

StrSQL = StrSQL &
"Round(CDbl(nz( ([OriginalCurrAmt]-[DisputedAmtOCur])*DLookUp("[Rate]","T
blCurStore","[ShrtCur]='"
& [OriginalCurr] & "' AND [Period] = '" &
Format([FinRecdDate],"mmm/yy") & "'"),0)),2) AS USDollarAmt "

I get an error "Expected: End of Statement".

I would be pleased if someone could help me with the syntax

The Complete code attached to an onclick event of a button on the
Report form is as follows:

Start of Code:

Dim TxtCriteria As String
Dim StrSQL As String
Dim qdf3 As QueryDef
Dim db As DAO.Database
Set db = CurrentDb

StrSQL = StrSQL & "SELECT TblInvoiceMain. SSANo,
TblInvoiceMain. ContractNo, TblInvoiceMain. FinRecdDate,
TblInvoiceMain. InvoiceNo, "
StrSQL = StrSQL & "TblInvoiceMain .OriginalCurr,
TblInvoiceMain. OriginalCurrAmt , TblInvoiceMain. DisputedAmtOCur , "
StrSQL = StrSQL &
"Round(CDbl(nz( ([OriginalCurrAmt]-[DisputedAmtOCur])*DLookUp("[Rate]","T
blCurStore","[ShrtCur]='"
& [OriginalCurr] & "' AND [Period] = '" &
Format([FinRecdDate],"mmm/yy") & "'"),0)),2) AS USDollarAmt "
StrSQL = StrSQL & "FROM TblInvoiceMain "
StrSQL = StrSQL & "ORDER BY TblInvoiceMain. ContractNo,
TblInvoiceMain. FinRecdDate; "

db.QueryDefs.De lete ("QryFrmReport" )

Set qdf3 = db.CreateQueryD ef("QryFrmRepor t", StrSQL)
RefreshDatabase Window
End of Code:

Thanks

Edward
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #1
1 2058
On 18 May 2004 04:16:35 GMT, Edward S <so******@devde x.com> wrote:

The "expected: end of statement" error can be debugged by setting a
breakpoint on that line, and in the Immediate window type:
?strSql
and paste taht string into a new query.
The query parser will show you where the problem is. Typically a
mismatch in parentheses.

-Tom.

Friends, I had posted this on "Microsoft.Publ ic.Access", But I did not
get a satisfactory response. I have been struggling for nearly 2 days
trying to crack this code. I really need help, could some one please
help me......
The Problem....

The USDollarAmt field is a calculated field, calculated
from the Original Currency Amount (OriginalCurrAm t) less the Disputed
Amount (DisputedAmtOCu r) both from the table "TblInvoiceMain " and then
multiplied with Currency Rate (Rate) that is stored in the table
"TblCurStore ", if the criteria matches the Currency (ShrtCur) {example
-'USD'} and the Period in the "TblCurStor e" to the field
"OriginalCur r" and "FinRecdDat e" stored in the Shortdate format
{example - "21-Jan-04"} in the TblInvoiceMain. I am having problems
with this particular line below:

StrSQL = StrSQL &
"Round(CDbl(nz (([OriginalCurrAmt]-[DisputedAmtOCur])*DLookUp("[Rate]","T
blCurStore", "[ShrtCur]='"
& [OriginalCurr] & "' AND [Period] = '" &
Format([FinRecdDate],"mmm/yy") & "'"),0)),2) AS USDollarAmt "

I get an error "Expected: End of Statement".

I would be pleased if someone could help me with the syntax

The Complete code attached to an onclick event of a button on the
Report form is as follows:

Start of Code:

Dim TxtCriteria As String
Dim StrSQL As String
Dim qdf3 As QueryDef
Dim db As DAO.Database
Set db = CurrentDb

StrSQL = StrSQL & "SELECT TblInvoiceMain. SSANo,
TblInvoiceMain .ContractNo, TblInvoiceMain. FinRecdDate,
TblInvoiceMain .InvoiceNo, "
StrSQL = StrSQL & "TblInvoiceMain .OriginalCurr,
TblInvoiceMain .OriginalCurrAm t, TblInvoiceMain. DisputedAmtOCur , "
StrSQL = StrSQL &
"Round(CDbl(nz (([OriginalCurrAmt]-[DisputedAmtOCur])*DLookUp("[Rate]","T
blCurStore", "[ShrtCur]='"
& [OriginalCurr] & "' AND [Period] = '" &
Format([FinRecdDate],"mmm/yy") & "'"),0)),2) AS USDollarAmt "
StrSQL = StrSQL & "FROM TblInvoiceMain "
StrSQL = StrSQL & "ORDER BY TblInvoiceMain. ContractNo,
TblInvoiceMain .FinRecdDate; "

db.QueryDefs.D elete ("QryFrmReport" )

Set qdf3 = db.CreateQueryD ef("QryFrmRepor t", StrSQL)
RefreshDatabas eWindow
End of Code:

Thanks

Edward
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
20776
by: KLAU | last post by:
I have a field that retrieves information from an expression in a query. I have used a DLookup function to get the calculated field from the query. However, the relationship is 1-to-many so one site could have many units. How do I have the DLookUp field value change to a newly calcuated field when I navigate through the units? please see example below: On the Form: A site can have many units.
4
440
by: David B | last post by:
I have a Public function which creates a back up copy of a back end. It works fine with the source path and source file as C:\folder\etc. I thought I would try to store the paths in a table so that any future changes could be made in the table rather than going into the code. I have been trying to get DLookup to work as below. Any reason why I should be getting probs ? I have tested these in a text box and they return as expected.
1
2378
by: Thelma Lubkin | last post by:
I am still struggling with trying to match a user supplied string with strings in a field of a table, where spaces are to be ignored. Arno suggested that I use the Dlookup function, but I apparently can't get its syntax right. Access gives me "Run-time error '2001' You canceled the previous operation" url: http://www.fontstuff.com/access/acctut15.htm, a set of 'Access Tips' has this to say about this error:
6
508
by: Don Sealer | last post by:
I've written this expression for a DLookup function. It works almost alright. What I'm trying to do is type in a description and the ID field (number) populates automatically. It works almost as I've said. It doesn't populate until I go to a new record. Then if I go back to the record the number is in the field. Instead of populating immediately it waits until I've created a new record. Am I making sense with this description. Here's...
2
2943
by: Diana | last post by:
I thought I had this process pretty well down pat, but I'm getting a syntax error on the following code: *****Code***** 'Check for users - can't get this to work... Dim strUser As String strUser = WUserName() If IsNull(DLookup("Permitted", "tblUsers", "Permitted = '" &
2
2271
by: Don | last post by:
Can someone help me fix my DLookup problem. I'm far from proficiency with Access. I've been creating databases for several years for work with the help of many of you and trial and error. I have used DLookup several times and I've actually re-created the same lookup just in different forms. Here's my problem. I'm using dlookup when I enter a part description it adds the part number for me. I choose the part description from a combo...
8
4560
by: MLH | last post by:
The following SQL returns PRECISELY what I want: SELECT TOP 1 tblCorrespondence.CorrespID, tblOutboundTypes.OTypDescription, tblCorrespondence.OutDate, tblCorrespondence.VehicleJobID, tblCorrespondence.OutType FROM tblOutboundTypes INNER JOIN tblCorrespondence ON tblOutboundTypes.OutType = tblCorrespondence.OutType WHERE (((tblCorrespondence.OutDate) Is Not Null) AND ((tblCorrespondence.VehicleJobID)=3)) ORDER BY...
0
1297
by: musman | last post by:
hey all, I have tried to use the select statement instead DLookUp function as i have sql server at my backend and access as my front end. But neither DLookUp function is working nor select state is working.... is there any other alternative way that i could make that run... my code is strEmail = DLookup("email", "owner", "name='Master_Table!'")
2
3642
by: Denise | last post by:
Front end is Access 2002, back end is linked Oracle tables. My users need to describe things in feet and inches and want to use the standard ' and " abbrevations. On a testing form I go to a record with double or single quotes in the location description and click a button to see if Access can tell me the ID number and find its way back to the original record. When the text contains double quotes the FindFirst works but the Dloookup...
0
8435
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8857
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8633
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7368
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6186
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5655
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4348
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2763
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1754
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.