i am using a create field script shown below
Public Function Add_field()
DoCmd.SetWarnings False
Dim dbs As Database
Dim myTable As TableDef
Dim myField As Field
Dim strMsg As String, strInput As String
'Initialise database
Set dbs = CurrentDb
'Get reference to table
Set myTable = dbs.TableDefs("Shift_Patterns"
'Create field object
Set myField = myTable.CreateField
myField.Type = dbBoolean
myField.Size = 50
'Add it to table
myTable.Fields.Append myField
'Update the lot
dbs.TableDefs.Refresh
For Each myField In myTable.Fields
Debug.Print myField.Name
Next myField
Set dbs = Nothing
End Function
My problem is if for some reason the user types in a name for a field but there is already a field with that name it gives an error out and asks if you want to debug.
I want to be able to compare the names of the fields with what the user has typed into the text box once they press the run command button and then if it already exists I want to be able to bring up my own message.
HOW?
Any help is greatly appreciated.
Many Thanks
Tim
Public Function Add_field()
DoCmd.SetWarnings False
Dim dbs As Database
Dim myTable As TableDef
Dim myField As Field
Dim strMsg As String, strInput As String
'Initialise database
Set dbs = CurrentDb
'Get reference to table
Set myTable = dbs.TableDefs("Shift_Patterns"
'Create field object
Set myField = myTable.CreateField
myField.Type = dbBoolean
myField.Size = 50
'Add it to table
myTable.Fields.Append myField
'Update the lot
dbs.TableDefs.Refresh
For Each myField In myTable.Fields
Debug.Print myField.Name
Next myField
Set dbs = Nothing
End Function
My problem is if for some reason the user types in a name for a field but there is already a field with that name it gives an error out and asks if you want to debug.
I want to be able to compare the names of the fields with what the user has typed into the text box once they press the run command button and then if it already exists I want to be able to bring up my own message.
HOW?
Any help is greatly appreciated.
Many Thanks
Tim