Private Sub Command42_Click()
If Not IsNull(Me![Text40]) Then
Dim stSQL
stSQL = "DELETE FROM [Allocated] ([Allocated To])" & _
" Values ('" & Me![Text40] & "')"
DoCmd.RunSQL stSQL
End If
DoCmd.Close acForm, "View/Update Test Equipment", acSavePrompt
DoCmd.OpenForm "View/Update Test Equipment", acNormal
End Sub
i do know that me being a starter with VBA is a pain and i will try harder next time.
Beyond what bob has said... I would like to put this to you...
Dim stSQL
As what? You are leaving out the most important part of the declaration, what type it should be.
Dim stSQL
as String in this case... that AS part is very important!
! vs . it is generaly accepted to use . where possible, this allows for "early binding" and makes your code less prown to errors. So instead of Me![Text40] use Me.Text40
Text40
Dont leave controls in their original default name, this is going to get hard to maintain FAST. If you would call this control txtToBeDeleted (or something) you
1) Instantly know what it is supposed to do
2) Can much more easily find the control on the form (even if it is big) because its Label will have a simular text to it.
[Allocated To]
Generaly try not to use spaces or special characters in any names anywhere. This will (eventually) give you problems. Keep it clean.
View/Update Test Equipment
Again the special characters and forms and queries and tables should have a naming convention in place. Tables start with tbl, queries qry, forms frm, etc.
This way it is much easier to refer back to something.
Hint on your problem:
Values is part of the "Insert into" statement, NOT delete.
Question
Why close and open the form?
Remark
An alternative to "DoCmd.RunSQL" is "CurrentDB.Execute" this will execute your query without those "annoying" popups saying "you are about to delete are you sure?"