I use the following 3 calls to add 3 fields to an Access db,
The sub is indicated below,
Only the first field ("lngMethodID") gets created. The other two fields ("txtReferencePoint") and ("txtSpaceForPole") do not get created. If I exit the db before each sub call then all fields get added. Do I need to add some "refresh field" action or other action.
Thanks in advance.
John
Code:
Call subCreateField("tblRootCanalTreatment", "lngMethodID", "dbLong", strPath, 606)
Call subCreateField("tblRootCanalTreatment", "txtReferencePoint", "dbText", strPath, 620)
Call subCreateField("tblRootCanalTreatment", "txtSpaceForPole", "dbText", strPath, 644)
The sub is indicated below,
Code:
Private Sub subCreateField(strTable As String, strField As String, strFieldType As String, strPath As String, lngVersion As Long)
Dim rstSerial As ADODB.Recordset
Set rstSerial = New ADODB.Recordset
rstSerial.Open "tblSerial", CurrentProject.connection, adOpenKeyset, adLockPessimistic
rstSerial.MoveFirst
If rstSerial!lngVersion < lngVersion Then
On Error Resume Next
DoEvents
Dim db142 As DAO.Database
Dim tdf142 As DAO.TableDef
Dim fld142 As DAO.Field
Dim prp142 As DAO.Property
'Initialize
Set db142 = OpenDatabase(strPath)
Set tdf142 = db142.TableDefs(strTable)
'Add a field to the table.
If strFieldType = "dbText" Then
Set fld142 = tdf142.CreateField(strField, dbText)
ElseIf strFieldType = "dbLong" Then
Set fld142 = tdf142.CreateField(strField, dbLong)
ElseIf strFieldType = "dbBoolean" Then
Set fld142 = tdf142.CreateField(strField, dbBoolean)
ElseIf strFieldType = "dbDate" Then
Set fld142 = tdf142.CreateField(strField, dbDate)
End If
tdf142.Fields.Append fld142
' after append new field create the property
' "DisplayControl" as a checkbox
If strFieldType = "dbText" Then
Set prp142 = fld142.CreateProperty("DisplayControl", dbText, acTextBox)
ElseIf strFieldType = "dbLong" Then
Set prp142 = fld142.CreateProperty("DisplayControl", dbLong)
ElseIf strFieldType = "dbBoolean" Then
Set prp142 = fld142.CreateProperty("DisplayControl", dbBoolean, acCheckBox)
ElseIf strFieldType = "dbDate" Then
Set prp142 = fld142.CreateProperty("DisplayControl", dbDate)
End If
' append the property to the field
fld142.Properties.Append prp142
db142.Close
'Clean up
Set fld142 = Nothing
Set tdf142 = Nothing
Set db142 = Nothing
rstSerial!lngVersion = lngVersion
rstSerial.update
End If
End Sub
Only the first field ("lngMethodID") gets created. The other two fields ("txtReferencePoint") and ("txtSpaceForPole") do not get created. If I exit the db before each sub call then all fields get added. Do I need to add some "refresh field" action or other action.
Thanks in advance.
John