thedon
thedon

Reputation: 11

Access VBA code format updating table using form and subform

I am currently learning access and VBA at the moment . I am trying to update table in My access 2013 database using a form which also has a sub form embedded in to it. The table is called exam categories and has two fields both are text fields called ExamCatCode and ExamDescription. I have created a delete button on the form which would delete the record that is selected on the subform which displays the results of table. Previously I had ExamCatCode as a number format field and I was using the following code to delete the record:

CurrentDb.Execute "Delete from ExamCategories " & _ " WHERE ExamCatCode=" & Me.ExamCategoriesSubform.Form.Recordset.Fields("ExamCatCode")

Now that I have changed the ExamCatCode to text format field the code is not working, I presume that I am missing a quote or an apostrophe somewhere, can some please set me straight. Thank you

Upvotes: 1

Views: 474

Answers (1)

Kostas K.
Kostas K.

Reputation: 8518

Try this:

CurrentDb.Execute "DELETE * FROM ExamCategories " & _
                  "WHERE ExamCatCode= '" & Me.ExamCategoriesSubform.Form![ExamCatCode] & "'", dbFailOnError

Upvotes: 1

Related Questions