473,398 Members | 2,165 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,398 software developers and data experts.

Expected: End of Statement

Hi All
I am getting the "Expected: End of Statement" message from my code:

strSQL = strSQL & "DLookUp("[ID]", "qryListCopiesToDelete", "[ID]" >1)))"

"[ID]" gets highlighted as an error! If I remove the quotation marks "qryListCopiesToDelete" becomes the problem etc. When I remove all quotes from the above script the warnings go but the script fails to work! How do I get the DLookup to read the query?

All queries were built in Query Design and work as plain queries, but when I place the code into vb - NOTHING!

Help please, I have spent ages on the web but to no avail.
Oct 30 '08 #1
11 8128
Stewart Ross
2,545 Expert Mod 2GB
Hi. Two problems with your statement: the first being that to include double quotes within a string you need to repeat the double quote character (it is after all a delimiter in VBA, and the VBA interpreter is seeing the end of your string as occurring just before your reference to the ID in your DLookup). The second error, which I also saw in a similar post you made earlier on this topic, is that your comparison statement is incorrect - the > 1 part is outside of the comparison.

Sorting these errors out, your StrSQL setup for the DLookup becomes:

Expand|Select|Wrap|Line Numbers
  1. strSQL = strSQL & " DLookUp(""[ID]"", ""qryListCopiesToDelete"", ""[ID]>1"")))"
which becomes
Expand|Select|Wrap|Line Numbers
  1. DLookUp("[ID]", "qryListCopiesToDelete", "[ID] >1")))
when run.

I am not convinced that this will do what you expect, however, as it is returning one ID from the set of all matching rows where the ID is > 1. I doubt very much that the one returned will in all cases be the one you need, but that is for you to sort out.

-Stewart
Oct 30 '08 #2
NeoPa
32,556 Expert Mod 16PB
In any case, quotes within SQL should be single-quotes rather than double-quotes (technically speaking - see Quotes (') and Double-Quotes (") - Where and When to use them). This would avoid the problem altogether (although not fix your logic - See Stewart's post).
Oct 30 '08 #3
Thanks Stewart (and NeoPa), the error message has gone away!! BUT as you predicted the script does not do want I want it to.

If you could help please!

I have a query which selects all duplicates from a table namely "qryListFirsts", (works fine).
I then created (in Query Design) another query which looks at the "qryListFirsts" and original Table to show all duplicate records - "qryListCopiesToDelete" (works fine).
My final query "qryDeleteDuplicates" whose SQL is:
Expand|Select|Wrap|Line Numbers
  1. DELETE tblMoneyDueBP.*, tblMoneyDueBP.ID
  2. FROM tblMoneyDueBP
  3. WHERE (((tblMoneyDueBP.ID)=DLookUp("ID","qryListCopiesToDelete","ID >1")));
is the script I am attempting to use in Visual Basic.
All work as they should when I run "qryDeleteDuplicates" via the Queries pane (albeit 1 record at a time gets deleted!!)

Therefore my problem remains as to why the above code fails to activate the relevant queries and achieve my goal when run within the VB area.

I hope this makes sense and that you may be able to assist.

Kind regards
Oct 31 '08 #4
NeoPa
32,556 Expert Mod 16PB
Thanks Stewart (and NeoPa), the error message has gone away!! BUT as you predicted the script does not do want I want it to.

If you could help please!
If you want help with this you will need to specify what you need. What is the latest version that you're trying? How is it failing?
I have a query which selects all duplicates from a table namely "qryListFirsts", (works fine).
I then created (in Query Design) another query which looks at the "qryListFirsts" and original Table to show all duplicate records - "qryListCopiesToDelete" (works fine).
My final query "qryDeleteDuplicates" whose SQL is:
Expand|Select|Wrap|Line Numbers
  1. DELETE tblMoneyDueBP.*, tblMoneyDueBP.ID
  2. FROM tblMoneyDueBP
  3. WHERE (((tblMoneyDueBP.ID)=DLookUp("ID","qryListCopiesToDelete","ID >1")));
is the script I am attempting to use in Visual Basic.
All work as they should when I run "qryDeleteDuplicates" via the Queries pane (albeit 1 record at a time gets deleted!!)

Therefore my problem remains as to why the above code fails to activate the relevant queries and achieve my goal when run within the VB area.
It does one at a time (only) because DLookup() is a Domain Aggregate function that returns only a single item.

Try instead :
Expand|Select|Wrap|Line Numbers
  1. DELETE tblMoneyDueBP.*
  2.  
  3. FROM tblMoneyDueBP INNER JOIN qryListCopiesToDelete
  4.   ON tblMoneyDueBP.ID=qryListCopiesToDelete.ID
  5.  
  6. WHERE qryListCopiesToDelete.ID>1
Oct 31 '08 #5
Thanks again for your time, much appreciated. I can see why your idea is much better, but still I cannot get it to work. Do I need to somehow run the queries in VB to get this script to function? Its as if the "qryListCopiesToDelete" is not being actioned. I dont know if this makes any sense, but I am starting to go mad!!

The only reason I need this in VB is to be able to point to varying tables depending on user ie tblInvoiceAB (for user AB) tblInvoiceBP (user BP) etc. As mentioned previously all worked well in Query Design.
Oct 31 '08 #6
NeoPa
32,556 Expert Mod 16PB
Two points here :
  1. Sometimes Action queries will only work when the underlying query is what is known as updatable. Your [qryListCopiesToDelete] query appears to be updatable, as you can delete items from it successfully. That is not to say that any action query based upon it must necessarily be so also (See Reasons for a Query to be Non-Updatable).

    When I find myself in that position, I often organise things in such a way as to update the table that I want to delete from. Usually I use a field in the table and set it to an otherwise not found value. Typically the string "DeleteMe", but anything can work, even numeric fields can be used if done properly. A very simple DELETE query can then follow on, deleting all records with the specially created value ("DeleteMe").
  2. Having separate tables for each entity who has invoices would not be a recommended approach. Check out Normalisation and Table structures for the full explanation of that. It may also help you resolve the other problem incidentally. A better approach generally, would be to have a single invoice table (tblInvoice for example) which contained a field that identified who the invoice was for. There are many benefits to this, some of which you will find in the linked article, and some of which you will become aware of as your experience leads you to different areas of the subject.
Nov 2 '08 #7
Thanks, cant wait to try it!! Your 1st idea would (thinking about it) work perfectly as it gives the table a value to search against, and therefore a unique record to find and delete.

Re your 2nd thought: I will look at this with interest, as going forward, it makes perfect sense to tie more areas together in diferent tables. However in my particular scenario I believe I should have individual tables to keep data secure from other users. (or would your suggestion be able to achieve this v. important criteria?)
Nov 3 '08 #8
NeoPa
32,556 Expert Mod 16PB
Well, you would generally choose to show only the data for a certain selected customer at any given time.

I doubt you'd want the customers to have direct access to the table data.
Nov 4 '08 #9
Bugran
6
Hello,

I'm not totally certain to your purpose of using SQL to accept a DLOOKUP. However, maybe the following will help you by bypassing the SQL statment and directly attributing a value to a variable from the DLOOKUP.

MYVARIABLE = DLookup("[ID]", "qryListCopiesToDelete", "[ID] >1")

Hope that helps you.
Bugran
Nov 4 '08 #10
Thanks Neopa solution 1 fixed the problem. I entered another field (Delete) into the table that updates with a "Yes", this gives me a referennce to delete all records against. ie If Delete field = Yes then delete. So simple its genius.

Brilliant again!! Thanks.

Re your last post I think I have misled you! My database is designed for multi users, for each user to have access only to his \ her records within the database. I thought the simplest route was to have individual tables for each user, rather than one huge table for all. My thought process being (rightly or wrongly) that the smaller the tables content the faster queries etc will run, whilst protecting the data from other users prying eyes.
Nov 4 '08 #11
NeoPa
32,556 Expert Mod 16PB
No worries. Glad I could help.

On the matter of multiple tables versus a single table with selection, it is actually possible to be in such a position as you describe, though generally shouldn't be an issue (does depend on certain settings and choices you may have made).

The downsides of your approach include extra complication of development etc.

At the end of the day it can still work that way if you prefer to do that, but I think it unlikely to be necessary. I don't know all the details of your database of course so that comes with no guarantees.
Nov 6 '08 #12

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

Similar topics

1
by: Phil Powell | last post by:
Here is the function ArraySearch: '-------------------------------------------------------------------------------------- 'ArraySearch will return an integer value indicating the first...
7
by: Graham James Campbell CS2000 | last post by:
Having a nightmare problem with this and would appreciate any and all help. The situation is I want to move from a webform and format the user inputted text into some html I am storing in a...
3
by: Matt | last post by:
When the ASP statement end with a _ character, then the next line cannot have comment ' character. Is that correct? Since I encountered the following error: Microsoft VBScript compilation...
5
by: andy.herrera | last post by:
I'm getting this Error Message. Expected ';' Please Select One: <form name="form1"> <<------------ Error is here. <select name="selectTrans" onChange="If (this.value == 'checkout')...
2
by: Edward S | last post by:
I would appreciate if someone could correct my SQL statement which is displaying a message Expected : End of Statement this statment is attached to a button on the form StrSQL = "PARAMETERS !!...
3
by: NeilH | last post by:
Hello All I was wondering if someone could offer a rather inexperienced person some advice. Im trying to get my asp page to look at an access data I created the following query in access...
35
by: Marchel | last post by:
For a long time I was a gib fan of Borland C++ Builder with VCL framework and never gave a second look in Microsoft products since I've seen MFC. Anyway, recently Borland decided out of the blue to...
39
by: eruanion | last post by:
Hi, I've been working on this for a while now and I can't seem to find out what is wrong with my code. I have 2 files one c3common.js which only contains javascript functions for my main html page...
3
by: eBob.com | last post by:
I've done a lot of programming but very little OOP. Would someone be kind enough to explain to me why I get a "declaration expected" on this statement: anythingarray(0) = new anything(3) ...
1
by: nosaj070 | last post by:
Hi, I'm working on a project and it is my first time implementing VBA with Access. I know my SQL Statement is close, but it obviously isn't perfect, if any of you can see what the error is I'd really...
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
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,...
0
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...
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
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,...
0
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...

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.