Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

create field problem

Status
Not open for further replies.

timotai

Technical User
Apr 13, 2002
119
GB
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
 
Debug to find out what the error number is. Then on that error number write your code



i.e.

if err.number = 12345 then
your code
end if
 
Debug to find out what the error number is. Then on that error number write your code



i.e.

if err.number = 12345 then
msgbox "my message............."
exit sub
end if
 
How do I fit that into my coding. The error occurs on the myTable.Fields.Append myField . If i put that script before or after myTable.Fields.Append myField it will not catch the error.
 
Just go it myself

I add

On Error GoTo err

and then add the If under

err:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top