Docmd.runsql readind a parameter from a textbox

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

What is the syntax to insert a new record into a Table. The table has only
two fields.
The first field should be a value from a textbox called textbox1 and the
second should be the value "Done"
I presume that I need to use Docmd.runsql and put my sql statment - but how
can I make it read a value from a textbox?
And do I need to set up a reference first - to Microsoft Dao 3.6 object
Library or other

Many thanks.

(A very confused) Mark
 
Mark,

Try this:

strSQL = "INSERT INTO TableName ( Field1, Field2 ) SELECT "
strSQL = strSQL & [Forms]![FormName].[textbox1] & " AS Expr1, 'Done' AS
Expr2"

DoCmd.RunSQL strSQL
'or
'CurrentDb.Execute strSQL

Make sure you change TableName, Field1, Field2, FormName, textbox1 to the
actual names!
Note: executing with DoCmd.RunSQL you will be prompted to append the
records; executing with CurrentDb.Execute you will not.

HTH,
Nikos
 
THanks,
Mark

Nikos Yannacopoulos said:
Mark,

Try this:

strSQL = "INSERT INTO TableName ( Field1, Field2 ) SELECT "
strSQL = strSQL & [Forms]![FormName].[textbox1] & " AS Expr1, 'Done' AS
Expr2"

DoCmd.RunSQL strSQL
'or
'CurrentDb.Execute strSQL

Make sure you change TableName, Field1, Field2, FormName, textbox1 to the
actual names!
Note: executing with DoCmd.RunSQL you will be prompted to append the
records; executing with CurrentDb.Execute you will not.

HTH,
Nikos

mark said:
What is the syntax to insert a new record into a Table. The table has only
two fields.
The first field should be a value from a textbox called textbox1 and the
second should be the value "Done"
I presume that I need to use Docmd.runsql and put my sql statment - but how
can I make it read a value from a textbox?
And do I need to set up a reference first - to Microsoft Dao 3.6 object
Library or other

Many thanks.

(A very confused) Mark
 
Back
Top