How can I insert a record in that table ?

  • Thread starter cmweb via AccessMonster.com
  • Start date
C

cmweb via AccessMonster.com

There is a form ORDER wich works with table TORDER
One of its text box is NAME

I need insert the NAME's data in the table TPERSONAL (other table) , in the
field NAMEPER

How can I insert a record in that table ?

Thanks in advance

CM
 
J

John Welch

Run an append query. You can put a button on your form that runs the query
via vba.
the code would look something like this:
docmd.runsql "Insert into tpersonal (nameper) select " & me.txtName

Note that I called the textbox "txtName" rather thean "name". It is a very
bad idea to have a field or a control on a form called "name" because that
is a reserved word that means something to Access and vba. Always use names
like "ClientName" or something like that.

for more info, look at append queries in help
hope this helps
 
J

John Nurick

Hi CM,

First, rename your Name field and the textbox bound to it. Having fields
and controls named "Name" is a guaranteed source of confusion, because
most Access objects, including fields, forms and controls, have Name
properties that store their names. Let's call them PersonName and
txtPersonName respectively.

Then do something like this, maybe in the ORDER form's AfterUpdate event
procedure (or maybe in a button's Click event procedure, or wherever):

Dim strSQL As String

'only append non-blank names
If Len(Nz(Me.txtPersonName.Value, "")) > 0 Then
'build single-record append query
strSQL = "INSERT INTO TPERSONAL (NAMEPER) " _
& "VALUES (""" & Me.txtPersonName.Value _
& """);"
'execute it
DBEngine(0)(0).Execute strSQL, dbFailOnError
End If
 
Top