Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I am trying to Delete a row from a subreport (my subreport used different columns values from different tables). But I've got a Data type mismatch error!
Below is the code I used:
CurrentDb.Execute "DELETE FROM StateBudget " & " WHERE S_ID = " & _
DLookup("ID", "States", "State='" & _
Me.subformStateBudget.Form.Recordset.Fields("State") & "'")
I think S_ID is a text value, so how can I change DLookup value to string or text?
You don't need to change the DLookUp value to a string, you need to pass it to SQL as a string (in quotes):
CurrentDb.Execute "DELETE FROM StateBudget " & " WHERE S_ID = """ & _
DLookup("ID", "States", "State='" & _
Me.subformStateBudget.Form.Recordset.Fields("State") & "'") & """"
Related
This question already has answers here:
Access DAO Inserting whole record into Another Recordset
(1 answer)
How to do INSERT into a table records extracted from another table
(9 answers)
Closed 1 year ago.
My question was deleted because of duplicate but this is not the case. My example uses an already made sql-string. The answer SO does not and where SO is referring to is way to complicated to implement in my solution. I try to edit my post and be more clearly about my issue. So I have a form which connects to an external database. My query qry_LIMS selects the relevant data.
LIDNUMMER = "([LIDNUMMER] = " & LIDNUMMER_Integer & ")"
MONSTERTYPE = "([MONSTERTYPE] = '" & Monstertype_String & "')"
MONSTERNDATUM = "([MONSTERNDATUM] = '" & Datum_String & "')"
strCriteria = LIDNUMMER & "And" & MONSTERTYPE & "And" & MONSTERNDATUM
task = "Select * from qry_LIMS where (" & strCriteria & ")"
Me.Form.RecordSource = task
What is the most easy way to insert all records from task into an other table named tbl_LIMS?
The named fields of my table tbl_LIMS are the same as qry_LIMS:
Lidnummer
Monstertype
Monsterndatum
I think the solution would rather easy but I do not seem to get it
INSERT INTO tbl_LIMS VALUES (task)
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I am performing in VBA an SQL query selecting per date. Everything is working until I specify the dates, as the code below:
conn.Open dbConnectStr
StartDate = "01/01/2015"
SQL_String = "SELECT * FROM database " & _
"WHERE date BETWEEN to_date('01/01/2015','dd/mm/yyyy') and to_date('31/12/2016','dd/mm/yyyy')"
recset.Close
conn.Close
But, when I put in a variable instead of dates I obtain an error multiple-step operation completed with one or more errors. Check each status values.
conn.Open dbConnectStr
StartDate = "01/01/2015"
EndDate = "31/12/2016"
SQL_String = "SELECT * FROM database " & _
"WHERE date BETWEEN to_date('" & StartDate & "','dd/mm/yyyy') and to_date('" & EndDate & "','dd/mm/yyyy')"
recset.Close
conn.Close
Anybody could suggest how to proceed?
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I already create a table Audit. When I try to insert table using this script:
sql = "Insert into "& myAudit &" (Date, Time, AuditCode , DetailsCode, CurData1, CurData2, CurData3, PrevData1, PrevData2 , PrevData3 , StaffID) values ('"& myTarikh &"','"& myMasa & "','" & myAuditCode & "', '" & myDetailsCode & "','"& myCurData1 &"','" & myCurData2 & "','" & myCurData3 & "','" & myPrevData1 & "','" & myPrevData2 & "','" & myPrevData3 & "', '" & myUserID &"')"
It diplays:
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[Oracle][ODBC][Ora]ORA-00904: "STAFFID": invalid identifier
How to fix this error?
STOP, use parameterized queries! Your current code is vulnerable for hackers and errors when using ' in one of the fields. Use something like this:
string query = "insert into myAudit (date, time, auditcode, ...) values (?, ?, ?, ...)";
OdbcCommand command = new OdbcCommand(query, connection);
command.Parameters.Add("?").Value = myTarikh;
command.Parameters.Add("?").Value = myMasa;
command.Parameters.Add("?").Value = myAuditCode;
Note the use of ?, since ODBC doesn't support parameter names, so the order of parameters matters!
Second, the issue is in the StaffID field, that doesn't seem to exist in your audit table.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm making a library system which allows student assistants to log in to the system. I have a table for student information to pull out information of the student assistants from instead of putting that same information in the student assistants accounts table because that would be a bit too redundant.
sqlSearch = "select * from tblSALogin where SA_ID = '" & txtUserName.Text & _
"' inner join tblStudentInfo on tblSALogin.StudentID = tblStudentInfo.StudentID"
I'm using the above SQL query expression to do that but it gives me a missing operator error and i don't know why. The syntax of the expression is correct and all of the tables required for the expression have already been related and have the required records.
You need to put the where after the join:
sqlSearch = _
"select * from tblSALogin " & _
"inner join tblStudentInfo on tblSALogin.StudentID=tblStudentInfo.StudentID " & _
"where SA_ID = '" & txtUserName.Text & "'"
Also note that you are vulnerable to SQL injection with this query, and you should look into using parameterized queries.
the join should be in the FROM clause, not in the WHERE clause
Try Like this
sqlSearch = "select tblSALogin.*,tblStudentInfo.* from tblSALogin inner join tblStudentInfo on tblSALogin.StudentID = tblStudentInfo.StudentID where SA_ID = '" & txtUserName.Text &"' "
Where clause should be come after Join.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
GROUP BY using parameters in SQL
Here is my SQL string for a OLEDB query of a .xlsx file
szSQL = "SELECT cawo_wo_id, wows_step_id, wows_description, wffj_cur_state_desc, cawo_wo_id & wows_step_id AS p5_id FROM [" & SourceSheet$ & "$" & sourceRange$ & "] WHERE [wows_description] like '%ECR%';"
I understand that named parameters are not supported by OLEDB, but why will it not work with a 'group by' using "?" as the parameter?
Like so:
szSQL = "SELECT cawo_wo_id, wows_step_id, wows_description, wffj_cur_state_desc, cawo_wo_id & wows_step_id AS p5_id FROM [" & SourceSheet$ & "$" & sourceRange$ & "] WHERE [wows_description] like '%ECR%' GROUP BY ?;"
Thanks for any help.
Doing that would group on the value that you send as the parameter value, and grouping on a literal value is not allowed.
If you want to group on different fields dynamically, you have to create the query dynamically, not put the field name in a parameter.