hi good day, i am having a problem about my program (VB 6.0)
i want to save data from my program to the access database (mS Access 2003)
the problem is that when i try to run the program, and click the button, theres an error about insert into syntax
this syntax is from my friend and it works perfectly for him but i dont know why did this happen to mine

heres my code

Private Sub registercmd_Click()
Set rcdst = New ADODB.Recordset
link.Execute "INSERT INTO Accounts(Username, Password, Fname, Lname, Age, Cnumber, Eadd, Add) VALUES ('" & logintxt.Text & "', '" & passwordtxt.Text & "', '" & firstnametxt.Text & "', '" & lastnametxt.Text & "', '" & agetxt.Text & "', '" & contacttxt.Text & "', '" & addresstxt.Text & "', '" & eaddtxt.Text & "')"
Unload Me
MsgBox "Successful"
homefrm.Show
End Sub

heres my module

Public link As New ADODB.Connection
Public rcdst As New ADODB.Recordset

Public Sub main()
Set link = New ADODB.Connection
link.Provider = "Microsoft.jet.OLEDB.4.0"
link.ConnectionString = "Data Source =" & App.Path & "\movierental.mdb"
link.CursorLocation = adUseClient
link.Open
End Sub

please help

Change it to

dim qry as string
qry = "INSERT INTO Accounts(Username, Password, Fname, Lname, Age, Cnumber, Eadd, Add) VALUES ('" & logintxt.Text & "', '" & passwordtxt.Text & "', '" & firstnametxt.Text & "', '" & lastnametxt.Text & "', '" & agetxt.Text & "', '" & contacttxt.Text & "', '" & addresstxt.Text & "', '" & eaddtxt.Text & "')"

debug.writeline(qry)

and post the output here.

Just an afterthought, password is a reserved word in some databases. Try

link.Execute "INSERT INTO Accounts(Username, [Password], Fname, Lname, Age, Cnumber, Eadd, Add) VALUES ('" & logintxt.Text & "', '" & passwordtxt.Text & "', '" & firstnametxt.Text & "', '" & lastnametxt.Text & "', '" & agetxt.Text & "', '" & contacttxt.Text & "', '" & addresstxt.Text & "', '" & eaddtxt.Text & "')"

Note that I replaced Password with [Password]

Edited 2 Years Ago by Reverend Jim

This article has been dead for over six months. Start a new discussion instead.