error:
In operator without () in query expression '(EnrollmentsTbl.UserName LIKE ? IN '' [;DATABASE=e:\web\mcfrsitcom0\htdocs\trackingHIPAA\App_Data\subsite.mdb])'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.OleDb.OleDbException: In operator without () in query expression '(EnrollmentsTbl.UserName LIKE ? IN '' [;DATABASE=e:\web\mcfrsitcom0\htdocs\trackingHIPAA\App_Data\subsite.mdb])'.
not sure why is asking for () in different place?
here is SELECT in ASPX vb.net
SelectCommand="SELECT EnrollmentsTbl.AutoNum, EnrollmentsTbl.UserName, EnrollmentsTbl.SubmitTime, EnrollmentsTbl.ClassName, EnrollmentsTbl.ClassDate, EnrollmentsTbl.ClassTime, EnrollmentsTbl.Enrolled, EnrollmentsTbl.WaitListed, EnrollmentsTbl.Instructor, EnrollmentsTbl.DateCompleted, EnrollmentsTbl.Completed, EnrollmentsTbl.Walkin FROM EnrollmentsTbl WHERE (EnrollmentsTbl.UserName LIKE ? IN '' [;DATABASE=e:\web\mcfrsitcom0\htdocs\trackingHIPAA\App_Data\subsite.mdb])"
From your other comments it sounds like you want to do something more like this:
SelectCommand = _
"SELECT EnrollmentsTbl.AutoNum, EnrollmentsTbl.UserName, EnrollmentsTbl.SubmitTime, " & _
"EnrollmentsTbl.ClassName, EnrollmentsTbl.ClassDate, EnrollmentsTbl.ClassTime, " & _
"EnrollmentsTbl.Enrolled, EnrollmentsTbl.WaitListed, EnrollmentsTbl.Instructor, " & _
"EnrollmentsTbl.DateCompleted, EnrollmentsTbl.Completed, EnrollmentsTbl.Walkin " & _
"FROM EnrollmentsTbl " & _
"WHERE EnrollmentsTbl.UserName IN " & _
"(" & _
"SELECT OtherColumnName " & _
"FROM [;DATABASE=e:\web\mcfrsitcom0\htdocs\trackingHIPAA\App_Data\subsite.mdb].OtherTableName" & _
")"
I just tried a similar query in C# using OleDb and it worked fine.
The IN operator looks for values that exist in a static list of values or the results of a subquery. You seem to be using it to find values in a database file.
You also combine it with the LIKE operator which doesn't make sense.
Perhaps if you explained better what you're trying to do an alternative could be found.
Related
I'm using Microsoft Access to develop a database app. An important feature the user would need is to automatically send an email update to all relevant stakeholders.
The problem is that I'm getting
Run-time error '3075' Syntax error in query expression.
Here it is below:
Set rs = db.OpenRecordset("SELECT StakeholderRegister.[StakeholderID], StakeholderRegister.[ProjectID], StakeholderRegister.[FirstName], StakeholderRegister.[LastName], StakeholderRegister.[EmailAddress] " & _
" FROM StakeholderRegister " & _
" WHERE (((StakeholderRegister.[ProjectID]=[Forms]![ChangeLog]![cboProjectID.Value])) ;")
Funny thing is that I created a query table on Access to create the relevant recordset and the turned on SQL view to copy the exact sql string that's above. That query works however it opens an Input Parameter box, whereas this code should be using the value typed into a forms text box as a matching criteria.
To use a variable as a parameter, do not include it within the quotes:
" WHERE StakeholderRegister.[ProjectID]=" & [Forms]![ChangeLog]![cboProjectID].[Value]
or just
" WHERE StakeholderRegister.ProjectID=" & Forms!ChangeLog!cboProjectID.Value
Note: You really only need the square brackets when there is something like a space in the name, which is not the best practice anyway.
I also took the liberty to remove the parentheses, as they are not needed in such a simple WHERE clause, and can cause more trouble than they are worth.
Try,
Dim strSQL As String
strSQL = "SELECT StakeholderRegister.[StakeholderID], StakeholderRegister.[ProjectID], StakeholderRegister.[FirstName], StakeholderRegister.[LastName], StakeholderRegister.[EmailAddress] " & _
" FROM StakeholderRegister " & _
" WHERE StakeholderRegister.[ProjectID]=" & [Forms]![ChangeLog]![cboProjectID].Value & " ;"
Set rs = Db.OpenRecordset(strSQL)
if [ProjectID] field type is text then
Dim strSQL As String
strSQL = "SELECT StakeholderRegister.[StakeholderID], StakeholderRegister.[ProjectID], StakeholderRegister.[FirstName], StakeholderRegister.[LastName], StakeholderRegister.[EmailAddress] " & _
" FROM StakeholderRegister " & _
" WHERE StakeholderRegister.[ProjectID]='" & [Forms]![ChangeLog]![cboProjectID].Value & "' ;"
Set rs = Db.OpenRecordset(strSQL)
I am new to Access VBA, I am using SQL statement to get data for creating excel file. The query uses a combo box [FBrpt_FbReason_Cbo] value as a criteria for the data. This is the first code I modified from the Access Query SQL mode:
SQL = "SELECT FB_Register.FB_Date_Received AS [Date received], FB_Register.FB_Resp_date AS [Response date], FB_Register.FB_Title AS [Feedback title], FB_Register.FB_Reason AS Reason " & _
"FROM FB_Register " & _
"WHERE (((FB_Register.FB_Reason)=[Forms]![Feedback_Reports]![FBrpt_FbReason_Cbo])) " & _
"ORDER BY FB_Register.FB_Date_Received DESC; "
It returns the error - Error number: 3061 = Too few parameters. Expected 1.
I then modified the Where line to:
"WHERE FB_Register.FB_Reason = " & [Forms]![Feedback_Reports]![FBrpt_FbReason_Cbo] & _
" ORDER BY FB_Register.FB_Date_Received DESC"
This returns the error – Error Number: 3075= Syntax error (missing operator) in query expression ‘FB_Register.FB_Reason = Positive feedback’.
In this case I have "Positive feedback" selected in the combo box. This code ‘FB_Register.FB_Reason = Positive feedback’ looks to me how it should be. What am I missing?
I figured it out, I needed the extra quotes - I believe - to turn the value into a string, even though its already a string
"WHERE FB_Register.FB_Reason = '" & [Forms]![Feedback_Reports]![FBrpt_FbReason_Cbo] & _ "' ORDER BY FB_Register.FB_Date_Received DESC"
Please can I ask that someone assist with the below SQL code. I am trying to open a recordset based on a variable BUSINESSTERM.
My SQL string looks like this:
sqlstr = "SELECT TblBusinessTerm.BusinessTermID, TblBusinessTerm.BusinessTerm, TblBusinessTerm.BusinessTermDesc, TblBusinessTerm.DomainCatID, " _
& " TblBusinessTerm.BusinessTermLongDesc, TblBusinessTerm.DomainID, TblBusinessSynonym.UpdatedBusinessTerm, * " _
& " FROM TblBusinessTerm LEFT JOIN TblBusinessSynonym ON TblBusinessTerm.BusinessTermID = TblBusinessSynonym.BusinessTermID " _
& " WHERE (TblBusinessTerm.BusinessTermID)= ; " & businessterm
Me.RecordSource = sqlstr
The issue is in the WHERE Statement. I keep on getting the error that I have to many parenthesis, and then when I remove the parenthesis I get an error
Syntax missing operator
Any assistance would be appreciated.
Thank you
Try this:
WHERE TblBusinessTerm.BusinessTermID=" & businessterm
And better:
WHERE TblBusinessTerm.BusinessTermID=" & Nz(businessterm, 0)
Ive been trying to get a query I ran in Access to run in VBA but I keep getting errors due to the number of exclamation marks I've been using. The statement I am using is
SQLstat = "SELECT tbl_Date_Check.DateofChecklist, tbl_Tasks.QuestionNumber,tbl_Tasks.Frequency, tbl_Tasks.Questions " _
& "FROM tbl_Tasks, tbl_Date_Check " _
& "WHERE (((tbl_Date_Check.DateofChecklist)=""" & [Forms]![Daily_Checker]![TxtDate] & """) And ((tbl_Tasks.Frequency) = """ & [Forms]![Daily_Checker]![ComFreq]"""))"
Any help would be great thanks
This can possibly be explained by the following SO question: What is the difference between single and double quotes in SQL?
This explains that you need to utilize single quotes '' to surround text in SQL in almost every instance. The fact that you are using double quotes "" may be what is causing the error.
I hope this helps.
-C§
It must read like this for dates:
SQLstat = "SELECT tbl_Date_Check.DateofChecklist, tbl_Tasks.QuestionNumber,tbl_Tasks.Frequency, tbl_Tasks.Questions " _
& "FROM tbl_Tasks, tbl_Date_Check " _
& "WHERE ((tbl_Date_Check.DateofChecklist = #" & Format([Forms]![Daily_Checker]![TxtDate], "yyyy\/mm\/dd") & "#) And (tbl_Tasks.Frequency = " & [Forms]![Daily_Checker]![ComFreq] & "))"
I am creating form in access in which i have to implement cascading combo boxes , data in lower combo box is dependent on its parent value selected by user. Here is form
on left side is structure of the table and on right side is form. Problem is I am getting error of data type mismatch , unable to understand why this is happening. In the afterupdate event of Diametre of Drill I am populating cutting speed . Whenever I press drop down of Cutting Speed "Datatype mismatch in criteria expression" occurs. Here is code of afterupdate event of Diametre of Drill
Private Sub cboDiameterDrilling_AfterUpdate()
cboCuttingSpeedDrilling.RowSource = "Select DISTINCT tblDrilling.cuttingSpeed " & _
"FROM tblDrilling " & _
`"WHERE tblDrilling.materials = '" & cboMaterialDrilling.Value & "' AND tblDrilling.diaOfDrill = '` `cboDiameterDrilling.Value ' " & _`
"ORDER BY tblDrilling.cuttingSpeed;"
End Sub
I think problem is in WHERE Clause . Any help would be greatly appreciated. Thank you
You've surrounded the reference to the object's value (cboDiameterDrilling.Value ) in single quotes.
AND tblDrilling.diaOfDrill = ' & cboDiameterDrilling.Value & "'"
Solution : AND tblDrilling.diaOfDrill = " & cboDiameterDrilling.Value & " " & _
I think you missed a ". Try:
Private Sub cboDiameterDrilling_AfterUpdate()
cboCuttingSpeedDrilling.RowSource = "Select DISTINCT tblDrilling.cuttingSpeed " & _
"FROM tblDrilling " & _
`"WHERE tblDrilling.materials = '" & cboMaterialDrilling.Value & "' AND tblDrilling.diaOfDrill = '" & cboDiameterDrilling.Value & "' " & _
"ORDER BY tblDrilling.cuttingSpeed;"
End Sub