I am calling the following in Form B from Form A using :
DelTsYes:
Forms(CalledBy).DoDeletesYes
Exit Sub
where "DoDeletsYes" is a Pro in Form B
###### this code works....ONTbl ...is the name of the Form B's recordsource.
Dim SQL As String
'DoCmd.SetWarnings False
MyRecord = Me.ID
SQL = "DELETE * " & _
"FROM ONTbl " & _
"WHERE (ONTbl.ID)= " & MyRecord
DoCmd.RunSQL SQL
Me.Requery
DoCmd.Close acForm, "MBDispInfoF"
### MBDispInfoF is Form A and is a form to use instead of the normal msgbox so I can customize the messages and display an Animation.
########## end of code that works
The following is ' ed out but is what I've been trying.
After several attempts I'm getting syntax "error in FROM clause". At one point I got as far as an error in the where clause but to be honest, I've forgotten how I got there.
So, is there a way for me to use variables in the SQL so I can put it in a Public Pro rather than having to hard code it in every form?
'MyRecord = Me.ID
'MyTable = Me.RecordSource
'msgbox MyTable
' SQL = "DELETE * " & _
'' "FROM " & MyTable & _
' "WHERE " & "((" & MyTable & ".ID) =)" & MyRecord
' DoCmd.RunSQL SQL
Me.Requery
DoCmd.Close acForm, "MBDispInfoF"
DoCmd.SetWarnings True
End Sub
I've tried to be as complete as possible but at this point my head is feeling foggy.