access2010
Registered User.
- Local time
- Today, 15:21
- Joined
- Dec 26, 2009
- Messages
- 1,021
UPDATE Investments01_tbl WHERE Investmentl_ID in (SELECT Investmentl_ID from ());
Private Sub Clear_Investigate_Yes_Click()
' Fuction Name ===> In the field Investigate, Change "Yes" => "No"
' Table Name ==> update Investments01_tbl
' Field Name ==> investigate
' Change Data in Field Investigate, from Yes to No
Dim strSQL As String
strSQL = "update Investments01_tbl" & _
"set investigate = 'No' " & _
"where Investmentl_ID in (SELECT Investmentl_ID from (" & Replace$(Me.RecordSource, ";", "") & "));"
CurrentDb.Execute strSQL
Me.Requery
End Sub
Thank you The_Doc_Man for your note, the code below is what we have tried.I looked at your code but I'm not going to execute someone else's code on my computer. (No disrespect intended.) You need to learn how to debug this kind of problem for yourself. Learn to use the debug features and learn how to examine variables at run-time to determine their content. You'll help yourself much better in the long run. I'm not going to leave you totally with no advice, though.
For this problem: You should set a breakpoint in the code at the entry point to the button-click event routine so that when you push the button on your form, you can single-step and examine the contents of that SQL string that you build. I suspect your "IN" clause in the SQL string behind the Change Yes button doesn't work correctly and thus your WHERE clause fails to select anything.
It would be nice if you would tell us a bit more than "does not work." Does it give an error? (If so, what error?) Does it make changes to the wrong records? "Does not work" is possibly one of the least useful descriptions you can give us because it gives us nothing to work with. We really do want to help folks, but you need to meet us halfway and give us a decent description of the behavior that you think is wrong.
One of the all-time great trouble-shooting methods ever devised is to create a SQL String from the concatenated bits and pieces.Thank you The_Doc_Man for your note, the code below is what we have tried.
Private Sub Clear_Investigate_Yes_Click()
' Fuction Name ===> In the field Investigate, Change "Yes" => "No"
' Table Name ==> update Investments01_tbl
' Field Name ==> investigate
' Change Data in Field Investigate, from Yes to No
CurrentDb.Execute "update Investments01_tbl" & _
"set investigate = 'No' " & _
"where Investmentl_ID in (SELECT Investmentl_ID from (" & Replace$(Me.RecordSource, ";", "") & "));"
Me.Requery
The error received is;
Run-time error ’3144’
Syntax error in UPDATE statement
Your suggestion will be appreciated. Nicole
Thank you Mike Krailo for your suggestion.I just looked at your first button that should change the "yes" to "no". It appears that the subquery is not populating a valid table to select from due to there not being a record source for your example form. The query depends on there being an sql string in the record source of the form and there is none.
Here is the sql string that is being generated from your code. Notice the subquery is not selecting from any table or query.
Code:UPDATE Investments01_tbl WHERE Investmentl_ID in (SELECT Investmentl_ID from ());
Thank you Pat Hartman for your suggestions. I have attached the table “Investments01_tbl” and used your debugging suggestion but did not change the query and a new error occurs Compile Error “Ambiguous name detected: Clear_Investigate_Yes_Click”This is ringing a bell. This is a very unusual error. There was an earlier thread where I went to great pains to explain what was wrong with the query and how to fix it but the information required was never forthcoming.
Me.RecordSource = the recordsource for the form named Analytics_F which is blank since the form isn't bound to any data, nor should it be. That means that the query raises an error. To make debugging easier, it is best to build SQL strings INTO a string and then execute the string. That will give you a way of seeing the string that you are sending to the query engine. This is the modified code to enable that.
Mike posted the string that is being sent so you can see the missing RecordSource Name.Code:Private Sub Clear_Investigate_Yes_Click() ' Fuction Name ===> In the field Investigate, Change "Yes" => "No" ' Table Name ==> update Investments01_tbl ' Field Name ==> investigate ' Change Data in Field Investigate, from Yes to No Dim strSQL As String strSQL = "update Investments01_tbl" & _ "set investigate = 'No' " & _ "where Investmentl_ID in (SELECT Investmentl_ID from (" & Replace$(Me.RecordSource, ";", "") & "));" CurrentDb.Execute strSQL Me.Requery End Sub
WHAT table or query do you want to run the update query against? I see no other table that includes the Investmentl_ID and you have no RI defined so I can't back into a non-identical name by finding a relationship.
Also, this query does not call for a sub query so it would be more efficient to use a join.
So, WHAT TABLE are you actually trying to update with the data from Investments01_tbl?
And last but not least, using special characters or embedded spaces in your object names makes them "offensive" to VBA and therefore you always have to encase them in square brackets [], Plus, there are places where VBA will actually change the offensive characters to underscores so that the code will work since these offensive names cannot be used in VBA.
Thank you GPGeorge for your suggestion which we entered as below, but we received an error when using your code.One of the all-time great trouble-shooting methods ever devised is to create a SQL String from the concatenated bits and pieces.
Like this:
Dim strSQL As String
...
strSQL =
"update Investments01_tbl" & _
"set investigate = 'No' " & _
"where Investmentl_ID in (SELECT Investmentl_ID from (" & Replace$(Me.RecordSource, ";", "") & "));"
Now, you can use Debug.Print to send that string to the immediate window:
Debug.Print strSQL
Now, you have a SQL string which can be tested in the query designer. That often returns more meaningful, useful error messages, making it easier for you to trouble-shoot the syntax yourself.
UPDATE Investments01_tbl SET Investments01_tbl.Investigate = "No"
WHERE Investments01_tbl.Investigate = "Yes";
CurrentDb.Execute "update Investments01_tbl " & _
"set investigate = 'No' " & _
"where investigate = 'Yes'"
UPDATE Investments01_tbl SET Investments01_tbl.Investigate = "No"
WHERE Investments01_tbl.Investigate = "Watch";
That was the point! There is an error in there somewhere. It's up to you to figure it out.Thank you GPGeorge for your suggestion which we entered as below, but we received an error when using your code.
Dim strSQL As String
strSQL =
"update Investments01_tbl" & _
"set investigate = 'No' " & _
"where Investmentl_ID in (SELECT Investmentl_ID from (" & Replace$(Me.RecordSource, ";", "") & "));"
Debug.Print strSQL
Regards Nicole
Thank you The_Doc_Man for your note, the code below is what we have tried.
Private Sub Clear_Investigate_Yes_Click()
' Fuction Name ===> In the field Investigate, Change "Yes" => "No"
' Table Name ==> update Investments01_tbl
' Field Name ==> investigate
' Change Data in Field Investigate, from Yes to No
CurrentDb.Execute "update Investments01_tbl" & _
"set investigate = 'No' " & _
"where Investmentl_ID in (SELECT Investmentl_ID from (" & Replace$(Me.RecordSource, ";", "") & "));"
Me.Requery
The error received is;
Run-time error ’3144’
Syntax error in UPDATE statement
Your suggestion will be appreciated. Nicole
"...WHERE Investmentl_ID = " & Me.Investmentl_ID & " ;"