I have this code and it will works like this
the Set db1 = OpenDatabase("C:\temp.mdb")
Code:On Error GoTo errorhandler Set db1 = OpenDatabase("C:\temp.mdb") Set td = db1.TableDefs("SubBrand") On Error Resume Next Set f1 = td.Fields(strString) If Err.Number = 0 Then MsgBox "Exists" Else Set td = db1.TableDefs("SubBrand") Set fl = td.CreateField(strString, dbText) td.Fields.Append fl End If Exit Sub errorhandler: If Not db1 Is Nothing Then db1.Close Err.Raise Err.Number Exit Sub
But not like this
or like thisCode:On Error GoTo errorhandler Set db1 = OpenDatabase("F:\VB\Baseball\database.mdb") Set td = db1.TableDefs("SubBrand") On Error Resume Next Set f1 = td.Fields(strString) If Err.Number = 0 Then MsgBox "Exists" Else Set td = db1.TableDefs("SubBrand") Set fl = td.CreateField(strString, dbText) td.Fields.Append fl End If Exit Sub errorhandler: If Not db1 Is Nothing Then db1.Close Err.Raise Err.Number Exit Sub
can somebody tell me why this won't work with my database and does with the temp database that I created when testing my code.Code:On Error GoTo errorhandler Set db1 = OpenDatabase(app.path & "\database.mdb") Set td = db1.TableDefs("SubBrand") On Error Resume Next Set f1 = td.Fields(strString) If Err.Number = 0 Then MsgBox "Exists" Else Set td = db1.TableDefs("SubBrand") Set fl = td.CreateField(strString, dbText) td.Fields.Append fl End If Exit Sub errorhandler: If Not db1 Is Nothing Then db1.Close Err.Raise Err.Number Exit Sub
by the way F: is an external HD if anyone is wondering




Reply With Quote