Inserting Into SQL Server

G

Guest

I have ODBC Connection to db and I'm trying to insert fldpatacct into a table
dbo_Anesth where the value is equal to the value on a form. The reason I do
it this way is that I look at several other fields before deciding to actuall
insert the record.

Dim mepatacct As String
Dim strSQLpat As String

mepatacct = Me.Text1.Value

strSQLpat = "INSERT INTO dbo_Anesth(fldpatacct)VALUES('" & mepatacct &
"')"
DoCmd.RunSQL , strSQLpat


DoCmd.OpenForm StDocName, , , stLinkCriteria
DoCmd.Close acForm, stDocName2
 
B

Brendan Reynolds

The SQL statement is the *first* argument to the RunSQL method, not the
second argument. In other words, this ...

DoCmd.RunSQL , strSQLpat

.... needs to change to ...

DoCmd.RunSQL strSQLpat
 
G

Guest

Thank you. It now looks like it's running, but it doesn't insert the record.
Could it be that something on the SQL Server side is not allowing updates.
 
B

Brendan Reynolds

Could be, but I'd expect an error message if that were the case. If you're
using 'On Error Resume Next' try commenting it out and see if you get an
error message. Otherwise, in the absence of any further information, I'm not
sure what to suggest.
 
S

Stefan Hoffmann

hi Sash,
Thank you. It now looks like it's running, but it doesn't insert the record.
Could it be that something on the SQL Server side is not allowing updates.
Use instead of DoCmd.RunSQL the following:

Dim db As DAO.Database

Set db = CurrentDb

db.Execute strSQLpat, dbFailOnError
MsgBox db.RecordsAffected


mfG
--> stefan <--
 

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