Access 2003.
Can a source name in table definition is set to be a query,
such as shown below ?
Set Table_Definition = Dbs.CreateTableDef(Query_Name)
The code below does not have any error, but it also
did enter the loop. The Query_Name is equal to
"Query_CrossTab", and the Field_Name is equal to "LV".
////////////////////////////////////////////////
Private Sub Insert_Records_Into_Table()
If The_Field_Exist("Query_CrossTab", "LV") Then
A = A + B
'CALL INSERT THE RECORD
End If
End Sub
////////////////////////////////////////////////
Function The_Field_Exist(Query_Name, Field_Name) As Boolean
Dim Dbs As DAO.Database
Dim Table_Definition As DAO.TableDef
Dim Field_Loop As DAO.Field
Debug.Print "Query_Name = ", Query_Name
Debug.Print "Field_Name = ", Field_Name
Set Dbs = CurrentDb
Set Table_Definition = Dbs.CreateTableDef(Query_Name)
For Each Field_Loop In Table_Definition.Fields
If Field_Loop.Name = Field_Name Then
Debug.Print Field_Name; " exists in " &
Table_Definition.Name
Public_If_The_Field_Exist = True
Exit For
Else
Debug.Print "The field does not exist"
Public_If_The_Field_Exist = False
End If
Next
End Function
Can a source name in table definition is set to be a query,
such as shown below ?
Set Table_Definition = Dbs.CreateTableDef(Query_Name)
The code below does not have any error, but it also
did enter the loop. The Query_Name is equal to
"Query_CrossTab", and the Field_Name is equal to "LV".
////////////////////////////////////////////////
Private Sub Insert_Records_Into_Table()
If The_Field_Exist("Query_CrossTab", "LV") Then
A = A + B
'CALL INSERT THE RECORD
End If
End Sub
////////////////////////////////////////////////
Function The_Field_Exist(Query_Name, Field_Name) As Boolean
Dim Dbs As DAO.Database
Dim Table_Definition As DAO.TableDef
Dim Field_Loop As DAO.Field
Debug.Print "Query_Name = ", Query_Name
Debug.Print "Field_Name = ", Field_Name
Set Dbs = CurrentDb
Set Table_Definition = Dbs.CreateTableDef(Query_Name)
For Each Field_Loop In Table_Definition.Fields
If Field_Loop.Name = Field_Name Then
Debug.Print Field_Name; " exists in " &
Table_Definition.Name
Public_If_The_Field_Exist = True
Exit For
Else
Debug.Print "The field does not exist"
Public_If_The_Field_Exist = False
End If
Next
End Function