how do you check to see if field exists?

niftysam

Registered User.
Local time
Today, 00:46
Joined
Jun 21, 2004
Messages
22
I know this must be very easy I just can't find it. Isdefined, isNull I thought might work but didn't. Does anyone have any idea how I can check to see if this table exists before I alter the table? Thanks so much!

Sam


Code:
    If (orsCompany("Pricing")) Then
        orsPricingField.Open "ALTER table [" & [Forms]![frmUpdatePricing]![Combo2] & "] add column [Pricing] STRING(30) " ' adding pricing field
    End If
 
Searching the forum you would have found something like this...
Code:
Sub TestTable()
    
    If TableExists("table1") = True Then
        MsgBox "table exists"
    Else
        MsgBox "table does not exist"
    End If
    
End Sub
Code:
Public Function TableExists(sTable As String) As Boolean
    
    Dim db As Database
    Dim tbl As TableDef
    Set db = CurrentDb()
    
    TableExists = False
    
    For Each tbl In db.TableDefs
        If tbl.NAME = sTable Then TableExists = True
    Next tbl
    
End Function
 
Thanks! It worked great.
 
Your welome!

Another satisfied customer. :D
 

Users who are viewing this thread

Back
Top Bottom