Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Other Forums
 MS Access
 More to the 'table exists' problem already answered...

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2003-09-22 : 07:33:22
Ben writes "Further to the SQL question asked on SQLTeam already
http://www.4guysfromrolla.com/webtech/sqlguru/q080400-1.shtml

I have a web app that will allow the use of both MS SQL 2000 and Access databases, and so I would like to determin if a table exists in MS Access.

Hope you can help"

X002548
Not Just a Number

15586 Posts

Posted - 2003-09-22 : 09:55:29
So your coding in the dark?

What happens if you do find an object exists with the name your looking for.

What are you going to with it then?

Do you know if there are any contraints on the objects or what they are? Any RI? What type of locking?

Anyway...I wrote this to get all the Table Objects from Access...


Public Function CreateCatalog()

Dim wks As Workspace
Dim db As Database
Dim dbMe As Database
Dim rs As Recordset
Dim tdf As TableDef
Dim qdf As QueryDef
Dim myfield As Field

Dim intResponse As Integer
Dim strDBPath As String
Dim strField As String
Dim strSQL As String
Dim strSQLTableName As String
Dim strSQLColumnName As String
Dim strDATA As String
Dim intRecordNumber As Integer


MsgBox "Subroutine to create a file of database objects"

DoCmd.Hourglass True

strDBPath = "\\Server\path\AccessDB.mdb"

strField = Chr(13)

Set wks = DBEngine.CreateWorkspace("temp", "sysadmin", "")
Set db = wks.OpenDatabase(strDBPath)
Set dbMe = CurrentDb

db.TableDefs.Refresh

strDATA = "TableName,ColumnName,ColumnType,Size,ColOrder,Required,AllowZeroLength"
intRecordNumber = 1
Print #1, strDATA ' Write record to file.
intRecordNumber = 1

'Loop trhough all the TableDefs in the database
For Each tdf In db.TableDefs
'Ignores system tables, which begin with "MSys" prefix
If InStr(tdf.Name, "MSys") = 0 Then

strDATA = tdf.Name

'Loop through all the fields in the TableDef and add them to the message and SQL strings
For Each myfield In tdf.Fields
strDATA = tdf.Name _
& "," & myfield.Name & "," & myfield.Type & "," & myfield.Size & "," & _
myfield.OrdinalPosition & "," & myfield.Required & "," & myfield.AllowZeroLength

intRecordNumber = intRecordNumber + 1
'Print #1, intRecordNumber, strDATA ' Write record to file.
Print #1, strDATA ' Write record to file.

'MsgBox strDATA
Next
End If
Next
Close #1 ' Close file.
DoCmd.Hourglass False
MsgBox "DONE!"
End Function





Brett

8-)

SELECT @@POST=NewId()

That's correct! It's an AlphaNumeric!
Go to Top of Page
   

- Advertisement -