Skip navigation

Sub main()
Dim conn
Dim sql
Set conn = CurrentProject.Connection

if tbExist(“teacher)=false then

sql = “CREATE TABLE teacher ” & _
“(teacherid varchar(5) NOT NULL, ” & _
“teacher varchar(50) NOT NULL, ” & _
“teacherLastname varchar(30), ” & _
“subjectid char(4) NOT NULL, ” & _
“CONSTRAINT teacher_pk PRIMARY KEY (teacherid), ” & _
“CONSTRAINT teacher_fk FOREIGN KEY (subjectid) ” & _
“REFERENCES subject(subjectid));”

conn.Execute sql

elseif fldExist(“teacher”,”teacherLastName”)=false then

sql=”ALTER TABLE teacher ADD teacherLastName varchar(30);”
conn.Execute sql

end if
set conn=nothing

End Sub
‘——————————————————————————–

Function fldExist(ByVal tbN As String, ByVal fldN As String) As Boolean
Dim Rss As New ADODB.Recordset
Rss.Open tbN, CurrentProject.Connection, 1
Dim i As Long
For i = 0 To Rss.Fields.Count – 1
If Rss(i).NAME = fldN Then
fldExist = True
Exit Function
End If
Next
fldExist = False
End Function
‘——————————————————————————–

Function tbExist(ByVal tbN As String) As Boolean
Dim Rss As New ADODB.Recordset
Rss.Open “Select name from MsysObjects”, CurrentProject.Connection, 1
Do While Not (Rss.EOF)
If Rss(0) = tbN Then
tbExist = True
Exit Function
End If
Rss.MoveNext
Loop
tbExist = False
End Function

ตอบคำถาม ไว้ที่ :http://access.crtrading.net/webboard/view.aspx?id=173
นามสมมติ : GTM

ใส่ความเห็น

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / เปลี่ยนแปลง )

Twitter picture

You are commenting using your Twitter account. Log Out / เปลี่ยนแปลง )

Facebook photo

You are commenting using your Facebook account. Log Out / เปลี่ยนแปลง )

Google+ photo

You are commenting using your Google+ account. Log Out / เปลี่ยนแปลง )

Connecting to %s

%d bloggers like this: