AllanBertelsen
Programmer
I need to delete a field from a table via VBA.
To close the table, so it can be altered, I load a form without a record source. The code for this form goes like this:
Private Sub Form_Load()
Dim strFelt As String
strFelt = Me.OpenArgs
DoCmd.Close acForm, "Adresser", acSaveYes 'Has the table as source
DoCmd.SetWarnings False
DoCmd.RunSQL "alter table Brugertabel drop column [" & strFelt & "]"
DoCmd.SetWarnings True
DoCmd.Close acForm, Me.Name
DoCmd.OpenForm "Adresser"
End Sub
The "ALTER TABLE" statement results in a runtime 3211 dispite this form is the only one that is open. If I copy the SQL-statement to the immediate window, reset code execution and run the SQL-statement from the immediate window - the field is dropped without further notification.
To close the table, so it can be altered, I load a form without a record source. The code for this form goes like this:
Private Sub Form_Load()
Dim strFelt As String
strFelt = Me.OpenArgs
DoCmd.Close acForm, "Adresser", acSaveYes 'Has the table as source
DoCmd.SetWarnings False
DoCmd.RunSQL "alter table Brugertabel drop column [" & strFelt & "]"
DoCmd.SetWarnings True
DoCmd.Close acForm, Me.Name
DoCmd.OpenForm "Adresser"
End Sub
The "ALTER TABLE" statement results in a runtime 3211 dispite this form is the only one that is open. If I copy the SQL-statement to the immediate window, reset code execution and run the SQL-statement from the immediate window - the field is dropped without further notification.