I've got a program i'm coding in Visual Basic 6 and it's linked to an Access 2003 database. I can pull records from a table ok, but I can't seem to find a way to insert them. No matter what I do I get an error. Is there something wrong with my SQL command or is my code just wrong?
Everything is running ok until I get to the second SQL Line. Basically I am trying to enter the text from several text boxes into the fields listed but when I click the command button, I get the message
Any Ideas?
Cheers,
Mitchel
Code:
Public Workbase As Database
Public WorkRS1 As Recordset
Public SQL As String
Private Sub cmdAddCustomer_Click()
Set Workbase = OpenDatabase("database.MDB")
SQL = "SELECT SchoolID FROM School WHERE SchoolName='" & cmbSchool.Text & "'"
Set WorkRS1 = Workbase.OpenRecordset(SQL)
SchoolID = WorkRS1.Fields.Item("SchoolID")
CustomerAddress = txtHouseNo.Text & " " & txtStreet.Text & " " & txtTown.Text & " " & txtPostcode.Text
txtDebug.Text = CustomerAddress
SQL = "INSERT INTO Customer(CustomerTitle, CustomerName, CustomerSurname, CustomerAddress, CustomerTel, SchoolID)VALUES('" & cmbTitle.Text & "','" & txtFirstName.Text & "','" & txtSurname.Text & "','" & CustomerAddress & "','" & txtTelephone.Text & "','" & SchoolID & "','"
Set WorkRS1 = Workbase.OpenRecordset(SQL)
CloseDB
End Sub
Everything is running ok until I get to the second SQL Line. Basically I am trying to enter the text from several text boxes into the fields listed but when I click the command button, I get the message
Run-time error '3346':
Number of query values and destination fields are not the same.
Any Ideas?
Cheers,
Mitchel