Facing an error in MS Access while getting the data From from to insert it into the table

58 views Asked by At

I am getting this error

Runtime error 3134

while clicking on the button in form to insert the data into table from the form.

Here's the code that I was trying to execute.

CurrentDb.Execute "INSERT INTO Main Sheet(Student Name, Pick Up Time, Home Address, Home City, School Hours, School Name, School Address, School City, Notes, School District, Parent Tel, Emergency Contact, Driver)" & _
    "VALUES(" & Me.stdName & "','" & Me.pickUpTime & "','" & Me.homeAddress & "','" & Me.homeCity & "','" & Me.schoolHours & "','" & Me.schoolName & "','" & Me.schoolAddress & "','" & Me.schoolCity & "','" & Me.notes & "','" & Me.schoolDistrict & "','" & Me.parentTel & "','" & Me.emergencyContact & "','" & Me.driver & "')"
    'refresh data in list on form
    MainForm.Form.Requery
1

There are 1 answers

0
Gustav On

You need brackets for table and field names with spaces and properly formatted string expressions for numeric and date fields:

Dim Sql As String

Sql = "INSERT INTO [Main Sheet] ([Student Name], [Pick Up Time], [Home Address], [Home City], [School Hours], [School Name], [School Address], [School City], Notes, [School District], [Parent Tel], [Emergency Contact], Driver) " & _
"VALUES ('" & Me.stdName & "',#" & Format(Me.pickUpTime, "hh\:nn" & "#,'" & Me.homeAddress & "','" & Me.homeCity & "','" & Me.schoolHours & "','" & Me.schoolName & "','" & Me.schoolAddress & "','" & Me.schoolCity & "','" & Me.notes & "','" & Me.schoolDistrict & "','" & Me.parentTel & "','" & Me.emergencyContact & "','" & Me.driver & "')"

CurrentDb.Execute Sql