Thanks for your answer. What do you mean 'standard module in public scope'?
If I try and enter the function directly, I just get error 3388 when I try and save the table.
This is the code I have:
Option Compare Database
Dim db As Database, rst As Recordset, strSQL As String
Dim tbls As TableDefs, tbl As TableDef, propDesc As Property
Dim strTable As String, strTDesc As String, strField As String, strFDesc As String, strType As String
Dim iCtr As Integer, iCt2 As Integer, fldLoop As Field
Function Code_Default(strCodeName As String) As Integer
' This routine returns the index of a parameter code which has been marked as Default
Set db = CurrentDb
strSQL = "SELECT CodeID FROM sys_Codes "
strSQL = strSQL & "WHERE (((sys_Codes.FieldName)='" & strCodeName & "') AND ((sys_Codes.CodeDefault)=True));"
Set rst = db.OpenRecordset(strSQL)
If rst.RecordCount < 1 Then
'MsgBox "Field: " & strCodeName & vbCr & "Value: " & strCodeValue, , "Error on Code"
Code_Default = 0
Exit Function
End If
If rst.RecordCount > 1 Then
MsgBox "Field: " & strCodeName & vbCr & "Value: " & strCodeValue, , "More than one Default found"
Code_Default = 0
Exit Function
End If
rst.MoveFirst
intLocal = rst!CodeID
rst.Close
Code_Default = intLocal
End Function