R
RedHeadedMonster via AccessMonster.com
Ok I have the following code:
Function CheckIfFieldExist(TableName As String, FieldName As String) As
Boolean
On Error GoTo CheckIfFieldExist_Err
' Function that check if a field exist in the table
' Return True if exist , and False if doesn't exist
Dim I As String
CheckIfFieldExist = True
I = Application.CurrentDb.TableDefs(TableName).Fields(FieldName).Name
Exit Function
CheckIfFieldExist_Err:
If Err = 3265 Then
CheckIfFieldExist = False
Else
MsgBox Error
End If
End Function
this is the other half of the code:
'Late
If CheckIfFieldExist("tblCDRLMetricsFinal2", "Late") Then
' Exist
Else
' Doesn't Exist
Dim dbCurLate As Database
Dim tdfLate As TableDef
Dim fldLate As Field
Set dbCurLate = CurrentDb()
Set tdfLate = dbCurLate.TableDefs("tblCDRLMetrics2Final")
Set fldLate = tdfLate.CreateField("Late", dbInteger)
tdfLate.Fields.Append fldLate
tdfLate.Fields.Refresh
End If
Problem is....regardless or whether or not "Late" exists (True or False The
code tries to create the "Late" field...of course if its already there I get
an error message. I dont want it to try and create if its there....I've
looked at this code until Im crosseyed...Someone see what the hell Im doing
wrong?
Thanx!
RHM
Function CheckIfFieldExist(TableName As String, FieldName As String) As
Boolean
On Error GoTo CheckIfFieldExist_Err
' Function that check if a field exist in the table
' Return True if exist , and False if doesn't exist
Dim I As String
CheckIfFieldExist = True
I = Application.CurrentDb.TableDefs(TableName).Fields(FieldName).Name
Exit Function
CheckIfFieldExist_Err:
If Err = 3265 Then
CheckIfFieldExist = False
Else
MsgBox Error
End If
End Function
this is the other half of the code:
'Late
If CheckIfFieldExist("tblCDRLMetricsFinal2", "Late") Then
' Exist
Else
' Doesn't Exist
Dim dbCurLate As Database
Dim tdfLate As TableDef
Dim fldLate As Field
Set dbCurLate = CurrentDb()
Set tdfLate = dbCurLate.TableDefs("tblCDRLMetrics2Final")
Set fldLate = tdfLate.CreateField("Late", dbInteger)
tdfLate.Fields.Append fldLate
tdfLate.Fields.Refresh
End If
Problem is....regardless or whether or not "Late" exists (True or False The
code tries to create the "Late" field...of course if its already there I get
an error message. I dont want it to try and create if its there....I've
looked at this code until Im crosseyed...Someone see what the hell Im doing
wrong?
Thanx!
RHM