The following code works when the user enters an alpha value followed by a numeric value (LL-15-KH) however when the user enters a numeric value first followed by an alpha value (15-HH-YY-2010) the code does not work. I get a type mismatch. I'm think the problems lies in the following statement; tdf.Fields(strFieldName).DefaultValue = " " & Text & " "
Any thoughts
Public Sub ChangeTableFieldDefaultValueText(strTableName As String, strFieldName As String, Text As String, strFormName As String)
On Error GoTo Err_ChangeTableFieldDefaultValue
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Set db = CurrentDb()
Set tdf = db.TableDefs(strTableName)
tdf.Fields(strFieldName).DefaultValue = " " & Text & " "
're-open calling form if name is passed
If strFormName <> "" Then
DoCmd.OpenForm strFormName, acNormal
End If
Exit_ChangeTableFieldDefaultValue:
Set tdf = Nothing
Set db = Nothing
Exit Sub
Err_ChangeTableFieldDefaultValue:
MsgBox Err.Number & " (" & Err.Description & ") in procedure ChangeTableFieldDefaultValue of Module DefaultsText"
Resume Exit_ChangeTableFieldDefaultValue
End Sub
How are you actually calling this procedure? This seems to work for me:
call ChangeTableFieldDefaultVal
I think the problem may be in how the procedure is called, or in the datatype of the underlying field (is it text, numeric, date...?)