GIVEN below is vbscript to connect to acess database and insert records into the table using forms

Private Sub Command1_Click()

Set rs = cn.Execute("insert into employee values('txtempname.text',txtempid.text,txtssn.text) ")
rs.Close
cn.Close
End Sub

Private Sub Form_Load()
datafile = "C:\mas.accdb"
With cn
.Provider = "microsoft.ACE.OLEDB.12.0"
.ConnectionString = datafile
.Open

End With
End Sub

GLOBAL SECTION

Global cn As New ADODB.Connection
Global rs As New ADODB.Recordset
Global datafile As String

I am getting error "no value given for one or more parameters ".please help me to fix this error?

I am new to vb programming.Kindly help me to correct the code

try the following

cn.Execute("insert into employee values('" & txtempname.text & "'," & txtempid.text & "," & txtssn.text & ") ")

@debasisdas
I tried the above suggestion .but got error 424 object required :(

Set rs = cn.Execute("insert into employee values('" & txtempname.text & "'," & txtempid.text & "," & txtssn.text & ") ")

Your problem is with the "Set rs = "part. cn is a connection that will handle all requests hence "cn.Execute"

Remove the Set rs = part -

cn.Execute("INSERT INTO employee VALUES('" & txtempname.text & "', " & txtempid.text & ", '" & txtssn.text & "') ")

.when i tried your code it was showing error in number of parameters so i included the field names also but still i am getting error "insert statement contain unknown values

cn.Execute ("INSERT INTO employee(empname,empid,ssn) VALUES('" & txtempname.Text & "', " & txtemplid.Text & ", '" & txtessn.Text & "') ")

It seems that you have a connection to database failure. Test your connection on your form load event, maybe needs a username or password etc. Once corrected, you should be able to insert data.

Thanks for the help AndreRet .It was connection failure.Now its working fine :)

I want to create a short form of a given name, i.e., when I input the name Pradip Kar, Sex:Male; the output will display PK0001M when another name will given by me like Barnali Sen,Sex:Female, the output will be BS0001F third time I will input the name Prasanta Dutta, Sex:Male, the output will be PD0002M, please help me.

This question has already been answered. Start a new discussion instead.