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:
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?
Code:
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)
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?
Comment