I can not Execute Simple Append Query

R

rebelscum0000

Topic: I can't Execute Simple Append Query

Dear All,

My problem began when I moved my code from my Forms to a Module, since
then I am having several Errors

Can someone please help me to determinate what I am doing wrong in this
Action Query?

Do I need to Dim dbMyKeywordININ As Database and rstMyKeywordININ
DAO.Recordset?

Do I need to Dim CurrentDb?

My Code

Sub MyKeyword_InsertsINTO_Tbl_MyKeywords_Tbl()

Dim dbMyKeywordININ As Database 'Current Dbs Default Table My
Keywod INSERT INTO
Dim rstMyKeywordININ As DAO.Recordset 'DAO.Recordset My Kwyword INSERT
INTO
Dim sQL3 As String 'Query, Variables more
strongly
Dim MyKeywordDe As String 'My Keyword Default

'Make sure Microsoft DAO 3.6 Library in included in the References

'On Error GoTo ErrorHandling
'Initialize Variables
MyKeywordDe = Forms!MainExclude_Form!Keyword
MsgBox MyKeywordDe

'Action Query Append
sQL3 = _
"INSERT INTO MyKeywords_Tbl ( ID, MyKeyword ) " & _
"SELECT MainExclude_Tbl.MyKeyword.ID, MainExclude_Tbl.MyKeyword " & _
"FROM MainExclude_Tbl " & _
"WHERE (((MainExclude_Tbl.MyKeyword) = '" &
Forms!MainExclude_Form!Keyword & "' )) "

Debug.Print sQL3

CurrentDb.Execute sQL3, dbFailOnError

Exit Sub
'ErrorHandling:
'MsgBox "Error Number: " & Err & " Descripcion " & Err.Description
End Sub
 
D

Daniel

Hi,

The thing which jumps out at me is
"SELECT MainExclude_Tbl.MyKeyword.ID, MainExclude_Tbl.MyKeyword " & _
because the first thing you're selecting doesn't look right. Maybe it
should be:
"SELECT MainExclude_Tbl.ID, MainExclude_Tbl.MyKeyword " & _

One thing which I find helpful is stepping through the code, and when
you get to the line where you generate your SQL statement, select the
SQL statement including quotation marks, and 'evaluate' it in the
immediate window. Then, paste the evaluated version into a new Query
and try to run it. The error messages are often helpful.

Daniel
 
R

rebelscum0000

Dear Daniel,

Thank you very much!

Now it WORKS!!

Once again THANK YOU

Kind Regards,
Antonio Macias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top