Insering a record using VB

D

David Mc

How can i insert a record in to a access table from a form
using VB (the reason is i have some special chcking in the
Form and theupdate is using parametres from the form.)

Thanks

David
 
N

nata

Hi you can do this using VBA,just create a table by name employee an
insert two columns emp_name and mgr_name.Assume you are fetching thes
two using a front end form designed using access.Assume that the fron
end form has two text boxes named txtemp and txtmgr

'----------------Code Begins----------------------


Dim rs As New ADODB.Recordset
Dim con As New ADODB.Connection
Set con = CurrentProject.Connection

Dim strsql As String

Dim empname,mgrname as String

Me.txtemp.SetFocus
empname=Me.txtemp.Text

Me.txtmgr.SetFocus
mgrname=Me.txtmgr.Text

strsql="INSERT INTO employee (emp_name,mgr_name) VALUES " & _
"('" & empname & "','" & mgrname & "') "

con.Execute (strsql)

'-----------------code ends-------------

Important thing is that the combination of single and double quotes ar
as is i have displayed.ie single quote nospace double quote spac
ampersand -> '" & parameter & "'

i think this would solve your proble
 
Top