Facing an error in MS Access while getting the data From from to

ghz 7months ago ⋅ 72 views

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

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

Answers

The error you're encountering, "Runtime error 3134", typically occurs when there's a syntax error in your SQL statement. In your code, there seems to be a syntax issue in the SQL string you're constructing.

Let's correct the syntax in your SQL statement. Ensure that you properly encapsulate string values within single quotes and separate each field name and field value pair with a comma. Here's the corrected SQL statement:

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 & "')"

In this corrected SQL statement:

  • Field names are enclosed in square brackets [ ] to account for any spaces or special characters in the field names.
  • String values (e.g., Me.stdName, Me.pickUpTime, etc.) are enclosed in single quotes ' '.
  • Each field name and field value pair is separated by a comma.

Please ensure that all field names and control names are correct and match the names of the fields in your table and controls on your form. Also, ensure that all string values are properly formatted.