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

Recommended Answers

All 3 Replies

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]

how about posting the error?..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.