Field Name in a Table

  • Thread starter Thread starter Vina
  • Start date Start date
V

Vina

How can i check if a Field Name exist in table.

I have a SQL that will insert the data from a table for
all ITEMS and PRICE. The PRICE field is not constant,
whatever the user select in the combo box in a form it
will take the ITEMS and the FIELD called the same as the
COMBO Box but in some case the data in the combo box
doesnt exist in the table so I wanted to see how I can
check if the field exist and if so then run the SQL if
not then just end.

Any ideas

Thanks
 
Hi,
Throw this function in a public module:

Public Function FieldExists(strTable As String, strField As String) As Boolean
Dim strName As String
On Error GoTo fe_err
strName = CurrentDb.TableDefs(strTable).Fields(strField).Name
FieldExists = True
Exit Function
fe_err:
If err.Number = 3265 Then
FieldExists = False
Else
MsgBox err.Description
End If
End Function

You can call it like this:

If FieldExists("yourTable","yourField") Then
'run your query
Else
'do something else
End If
 
Back
Top