execute insert into statement not working

pablavo

Registered User.
Local time
Yesterday, 19:25
Joined
Jun 28, 2007
Messages
189
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.

Code:
  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:)
 
Try changing CurrentDb.Execute to Docmd.RunQuery, this will give you popups but will also show you any errors this query runs into.
 
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.

Code:
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
 
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?
 

Users who are viewing this thread

Back
Top Bottom