What did you copy to the Command_Click event?
If all you copied was that SQL statement, no wonder it didn't work. You need
to tell Access to run the query:
Dim strSQL As String
strSQL = "INSERT INTO A " & _
"SELECT TX.* " & _
"FROM TX " & _
"WHERE (((""maintid"")=[forms]![compareresult].[maintid1]))"
CurrentDb.Execute strSQL, dbFailOnError
Of course, I'm not sure what that SQL supposed to be doing. It's comparing
the literal string maintid to whatever's in the control named maintid1 on
form compareresult. If that control contains the text "maintid", it's going
to put everything from table TX into table A. If that control doesn't
contain the text "maintid", it's not going to put anything in table A.
I suspect you want to select those rows in table TX where field maintid is
equal to what's in the control on the form. That means your SQL should be:
strSQL = "INSERT INTO A " & _
"SELECT TX.* " & _
"FROM TX " & _
"WHERE maintid=" & [forms]![compareresult].[maintid1]
assuming maintid is a numeric field, or the following if it's text:
strSQL = "INSERT INTO A " & _
"SELECT TX.* " & _
"FROM TX " & _
"WHERE maintid=" & Chr(34) & [forms]![compareresult].[maintid1] &
Chr(34)
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
Nova said:
I copy code from query, It work normal.
INSERT INTO A
SELECT TX.*
FROM TX
WHERE ((("maintid")=[forms]![compareresult].[maintid1]));
After that I try to copy code to form [compareresult] on command_click event.
It does not works Why? Can you help me please.