I am trying to add a column to a table.
It is easy if it is not there
CurrentDb.Execute "ALTER TABLE TableName ADD COLUMN FieldName Type(Char length)"
When it is there, then of course I error out. I am trying to set a function to check if it is there or not. If it is not there then make the Field and update from another source. If it is there, then only update from the other source.
I think it is how I am referencing the function as I error out on the red Italicized, Bold and underlined code in the function. Am I calling the function incorrectly or am I putting in the incorrect information in the call code?
See below
Thanks
Code:
Public Sub AddColumn_Click()
Dim strSQL As String
strSQL = "UPDATE Data INNER JOIN Units ON Data.Unit = Units.Units SET Data.Netbase = [Units].[Netbase] WHERE (([Units].[Units]=[data].[Unit]));"
Call FieldExist("Data", "Netbase")
CurrentDb.Execute "ALTER TABLE Data ADD COLUMN Netbase Text(20)"
DoCmd.RunSQL strSQL
Exit Sub
Call FieldExist("Data", "Netbase")
DoCmd.RunSQL strSQL
End Sub
Function =
Code:
Public Function FieldExist(sField As String, sTable As String) As Boolean
Err.Clear
If (DCount(sTable, sField) = 0) And Err Then
FieldExist = False
Else: FieldExist = True
End If
End Function