Inserting Into SQL Server

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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
 
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.
 
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.
 
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 <--
 
Back
Top