帮忙:查找错误,一个VBA中的数据库技术的程序。谢谢
<P> 这个程序是照着书复制的,但编译的时候,还是有问题</P><P>系统提示红色的地方有问题,麻烦各位大侠帮忙,小弟不胜感激</P>
<P>Public Sub CreateDatabase()<BR> <BR> Dim NewWs As Workspace <BR> Set NewWs = DBEngine.Workspaces(0) <BR> <BR> Dim NewDb As Database <BR> Dim mdbName As String<BR> mdbName = CurDir() & "\SAMPLE\Authors.mdb"<BR> <FONT color=#dd2222>Set NewDb = NewWs.CreateDatabase(mdbName, dblangGeneral)<BR></FONT> <BR> <BR> Dim NewTbl1 As TableDef, NewTbl2 As TableDef<BR> Set NewTbl1 = NewDb.CreateTableDef("Youth")<BR> Set NewTbl2 = NewDb.CreateTableDef("Works")<BR> <BR> <BR> Dim F1 As Field, F2 As Field, F3 As Field, F4 As Field<BR> Dim F5 As Field, F6 As Field, F7 As Field, F8 As Field<BR> Dim F9 As Field, F10 As Field, F11 As Field<BR> <BR> Set F1 = NewTbl1.CreateField("AuthorID", dbText, 6) <BR> Set F2 = NewTbl1.CreateField("FirstName", dbText, 20) <BR> Set F3 = NewTbl1.CreateField("LastName", dbText, 20) <BR> Set F4 = NewTbl1.CreateField("Age", dbInteger) <BR> Set F5 = NewTbl1.CreateField("Address", dbText, 30) <BR> Set F6 = NewTbl1.CreateField("City", dbText, 20) <BR> Set F7 = NewTbl1.CreateField("Proviance", dbText, 20) <BR> Set F8 = NewTbl1.CreateField("Phone", dbText, 10) <BR> Set F9 = NewTbl1.CreateField("Email", dbText, 20) <BR> <BR> Set F10 = NewTbl2.CreateField("AuthorID", dbText, 6)<BR> Set F11 = NewTbl2.CreateField("WorksName", dbText, 30) <BR> <BR> <BR> NewTbl1.ValidationRule = "Age > 0"<BR> NewTbl1.ValidationText = "职员年龄不能小于零!"<BR> </P>
<P> NewTbl1.Fields.Append F1<BR> NewTbl1.Fields.Append F2<BR> NewTbl1.Fields.Append F3<BR> NewTbl1.Fields.Append F4<BR> NewTbl1.Fields.Append F5<BR> NewTbl1.Fields.Append F6<BR> NewTbl1.Fields.Append F7<BR> NewTbl1.Fields.Append F8<BR> NewTbl1.Fields.Append F9<BR> NewTbl2.Fields.Append F10<BR> NewTbl2.Fields.Append F11<BR> <BR> <BR> NewDb.TableDefs.Append NewTbl1<BR> NewDb.TableDefs.Append NewTbl2<BR> <BR> <BR> NewDb.Close<BR> Set NewDb = Nothing</P>
<P>End Sub</P> <P>如果你因用的为“Microsoft DAO 3.51 Object Library”上面的代码没有问题的。</P>
<P> </P>
<P>如果你因用的为“Microsoft DAO 3.6 Object Library”的话,那么</P>
<P><FONT color=#dd2222>Set NewDb = NewWs.CreateDatabase(mdbName, dblangGeneral)</FONT></P>
<P><FONT color=#dd2222>应改为</FONT></P>
<P><FONT color=#dd2222>Set NewDb = NewWs.CreateDatabase(mdbName, dblangGeneral,dbEncrypt)</FONT></P>
<P><BR> </P>
页:
[1]