473,471 Members | 4,637 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

SQL Multiple WHERE Statements with Date Variables Problem

6 New Member
I'm trying to run a query using SQL in VBA. I want the query to only show data that matches 3 criteria. I'm using a WHERE statement with 2 AND's and my database doesn't seem to like that. I am also using date variables (startdate and enddate) in my SQL statement. My query code is below:

Expand|Select|Wrap|Line Numbers
  1. Set employeeOEE = db.OpenRecordset("SELECT [Query-OEE].[Machine Type], [Query-OEE].[Date], [Query-OEE].[Employee Name] FROM [Query-OEE] WHERE [Query-OEE].[Machine Type]= " & departtype & " AND [Query-OEE].[Date] BETWEEN " & startdate & " AND " & enddate & " AND [Query-OEE].[Employee Name]= " & empname & ";", dbOpenDynaset)
The error I'm getting is "Run-Time Error 3075" Syntax error (missing operator) in Query expression. [Query-OEE].[Machine Type]= " & departtype & " AND [Query-OEE].[Date] BETWEEN " & startdate & " AND " & enddate & " AND [Query-OEE].[Employee Name]= " & empname & ";", dbOpenDynaset)

If I take out '"[Query-OEE].[Date] BETWEEN " & startdate & " AND " & enddate & "' I don't get an error. This is my first time using a date variable (which are entered in a form before this part of the code) so I may not have the syntax right on that portion.

I'm sure I just have something minor messed up. Can somebody help me out please?
Sep 15 '10 #1

✓ answered by liimra

Try this
Expand|Select|Wrap|Line Numbers
  1. Between #" & [startdate] & "# And #" & [endDate] & "#"
Regards,
Ali

3 2292
liimra
119 New Member
Try this
Expand|Select|Wrap|Line Numbers
  1. Between #" & [startdate] & "# And #" & [endDate] & "#"
Regards,
Ali
Sep 15 '10 #2
JaketheSnake27
6 New Member
That was it! Thank you!
Sep 16 '10 #3
liimra
119 New Member
You are most welcome.

Regards,
Ali
Sep 16 '10 #4

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

Similar topics

2
by: Shmuel | last post by:
Is it possible to query multiple statements at once? Like: $query = "set @p := 1; select @p + 1"; $results = mysql_query($query); I'm thinking of PHP4. There is in mysqli the prepare...
1
by: DrewM | last post by:
I'm still thinking about session variables :-) Does anyone know the detail of how session variables are actually stored? The question I'm trying to answer is: Is it more efficient to store and...
1
by: Erik Haugen | last post by:
This item in the C++ faq: http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-38.5 discusses macros with multiple statements. The problem is that a macro such as #define...
4
by: DG | last post by:
Hi, Can anyone advise how to execute multiple statements in a single query batch. For example- update customers set customer_name = 'Smith' where customer_name = 'Smyth'; select * from...
2
by: Annie D via AccessMonster.com | last post by:
Hi, Is it possible to use multiple statements in SQL?? (I’ve never used it before) : I have one query that i'm working with, The statements I want to use are as below, they all work...
2
by: Thomas Beyerlein | last post by:
I am binding dates to a textbox, the date is stored in SQL in a datetime field. When it gets bound it turns it into a long date (Sunday, Dec. 25 2005), in SQL when viewing the table it views as a...
1
by: arthy | last post by:
Hi, Is it possible to execute multiple statements on to the database using a single dbconnection object.what is the drawback in using .If not possible ,then how can the execution of multiple...
7
by: Pam Poulos | last post by:
I have a form where users input some dates, these dates are then written to date variables. I need to clear out the date variables with either an empty string or a null value. Currently, I am...
2
by: Brad Pears | last post by:
I am working on a vb.net 2005 project using sql server 2000 as the backend . I am having a bit of problems with date variables... Here is the scenario... I have a table that includes a couple...
0
by: harsha318 | last post by:
Hi I need to have a single query and which can have multiple statements For eg: string str = string.Empty; str = "select * from Customers;Select * from Orders"; iDB2Connection iDB2con =...
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
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...
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
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.