PDA

Click to See Complete Forum and Search --> : How can I get Table Name in Database by VB Coding?


pavinda
Nov 24th, 1999, 11:41 AM
I would like to Create Table in the database .But I have to check that the database has this table yet. How can I know ? And After that How can I Create table in code?

netSurfer
Nov 24th, 1999, 11:50 AM
This is how I do it, not necessarily the best way, but it works. It will check the current database for a table, if it exists then will set booTable to true. If it doesn't find anything then it will make a table of the structure defined in strTable. Let me know if you have a problem or if this doesn't work.

Matthew
matthewbryan@hotmail.com


------
dim strtemp as string, dbsNew as database
dim intCounter as integer, intI as integer
dim strTable as string, booTable as boolean
strtemp = "CSVTabletemp" 'table name
booTable = false
Set dbsNew = CurrentDb

strTable = "CREATE TABLE CSVTabletemp " _
& "(temp text (255), temp2 text (255), temp3 text (255), " _
& "temp4 text (255), temp5 text (255), temp6 text (255), temp7 text (255), " _
& "temp8 text (255), temp9 text (255), temp10 text(255), " _
& "temp11 text (255), temp12 text (255), temp13 text (255), temp14 text (255));"

intCounter = dbsNew.TableDefs.Count - 1
'the next should loop through to make sure the table doesn't exist, if it does, delete it
For intI = 0 To intCounter
If dbsNew.TableDefs(intI).Name = strtemp Then
booTable = true
Exit For
End If
Next intI

if booTable = false then
dbsNew.Execute strTable 'creates the temp table
end if

-------