View Full Version : execute insert into statement not working


pablavo
08-19-2008, 12:05 AM
Hi there.

I have a similar post that hasn't really been answered probably due to it being fairly long and complex. So, I've broken it down.

I'm trying to execute code from a command button on a form to add a new record to a table.

CurrentDb.Execute ("INSERT INTO dbo_ComplaintDetail (PersonID) VALUES (" & Me.PersonID.Value & ");")


This is not working and know new record is being added. Is my syntax wrong? The me.PersonID.Value is from the ID on the form that will match the field in the new record.

Hope someone can help:)

namliam
08-19-2008, 12:13 AM
Try changing CurrentDb.Execute to Docmd.RunQuery, this will give you popups but will also show you any errors this query runs into.

WayneRyan
08-19-2008, 10:35 AM
Pablavo,

In addition to the Mailman's suggestion, you can assist yourself and others
by getting more information.

Add a string variable to your code.

Set a breakpoint on the CurrentDb.Execute line.


Dim sql As String
sql = "INSERT INTO dbo_ComplaintDetail (PersonID) VALUES (" & Me.PersonID.Value & ");"
CurrentDb.Execute sql


When it breaks, paste the value of the sql string into the query SQL view and run it.
It will tell you exactly what is wrong.

You can also paste the value of the sql string back here if you need.

Wayne

FoFa
08-19-2008, 01:29 PM
Seems easy enought to create an Append query that pulls the value from the form, then you can use DOCMD.OpenQuery to run it.
No?