feiniao82 发表于 2005-7-15 21:32:00

帮忙:查找错误,一个VBA中的数据库技术的程序。谢谢

<P>&nbsp;这个程序是照着书复制的,但编译的时候,还是有问题</P>
<P>系统提示红色的地方有问题,麻烦各位大侠帮忙,小弟不胜感激</P>

<P>Public Sub CreateDatabase()<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Dim NewWs As Workspace&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Set NewWs = DBEngine.Workspaces(0) <BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Dim NewDb As Database <BR>&nbsp;&nbsp;&nbsp; Dim mdbName As String<BR>&nbsp;&nbsp;&nbsp; mdbName = CurDir() &amp; "\SAMPLE\Authors.mdb"<BR>&nbsp;&nbsp;&nbsp; <FONT color=#dd2222>Set NewDb = NewWs.CreateDatabase(mdbName, dblangGeneral)<BR></FONT>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Dim NewTbl1 As TableDef, NewTbl2 As TableDef<BR>&nbsp;&nbsp;&nbsp; Set NewTbl1 = NewDb.CreateTableDef("Youth")<BR>&nbsp;&nbsp;&nbsp; Set NewTbl2 = NewDb.CreateTableDef("Works")<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Dim F1 As Field, F2 As Field, F3 As Field, F4 As Field<BR>&nbsp;&nbsp;&nbsp; Dim F5 As Field, F6 As Field, F7 As Field, F8 As Field<BR>&nbsp;&nbsp;&nbsp; Dim F9 As Field, F10 As Field, F11 As Field<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Set F1 = NewTbl1.CreateField("AuthorID", dbText, 6)&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Set F2 = NewTbl1.CreateField("FirstName", dbText, 20)&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Set F3 = NewTbl1.CreateField("LastName", dbText, 20)&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Set F4 = NewTbl1.CreateField("Age", dbInteger)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Set F5 = NewTbl1.CreateField("Address", dbText, 30)&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Set F6 = NewTbl1.CreateField("City", dbText, 20)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Set F7 = NewTbl1.CreateField("Proviance", dbText, 20)&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Set F8 = NewTbl1.CreateField("Phone", dbText, 10)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Set F9 = NewTbl1.CreateField("Email", dbText, 20)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Set F10 = NewTbl2.CreateField("AuthorID", dbText, 6)<BR>&nbsp;&nbsp;&nbsp; Set F11 = NewTbl2.CreateField("WorksName", dbText, 30)&nbsp; <BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; NewTbl1.ValidationRule = "Age &gt; 0"<BR>&nbsp;&nbsp;&nbsp; NewTbl1.ValidationText = "职员年龄不能小于零!"<BR>&nbsp;&nbsp;&nbsp; </P>
<P>&nbsp;&nbsp;&nbsp; NewTbl1.Fields.Append F1<BR>&nbsp;&nbsp;&nbsp; NewTbl1.Fields.Append F2<BR>&nbsp;&nbsp;&nbsp; NewTbl1.Fields.Append F3<BR>&nbsp;&nbsp;&nbsp; NewTbl1.Fields.Append F4<BR>&nbsp;&nbsp;&nbsp; NewTbl1.Fields.Append F5<BR>&nbsp;&nbsp;&nbsp; NewTbl1.Fields.Append F6<BR>&nbsp;&nbsp;&nbsp; NewTbl1.Fields.Append F7<BR>&nbsp;&nbsp;&nbsp; NewTbl1.Fields.Append F8<BR>&nbsp;&nbsp;&nbsp; NewTbl1.Fields.Append F9<BR>&nbsp;&nbsp;&nbsp; NewTbl2.Fields.Append F10<BR>&nbsp;&nbsp;&nbsp; NewTbl2.Fields.Append F11<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp; <BR>&nbsp;&nbsp;&nbsp; NewDb.TableDefs.Append NewTbl1<BR>&nbsp;&nbsp;&nbsp; NewDb.TableDefs.Append NewTbl2<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp; <BR>&nbsp;&nbsp;&nbsp; NewDb.Close<BR>&nbsp;&nbsp;&nbsp; Set NewDb = Nothing</P>
<P>End Sub</P>

wylong 发表于 2005-7-18 13:08:00

<P>如果你因用的为“Microsoft DAO 3.51 Object Library”上面的代码没有问题的。</P>
<P>&nbsp;</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>&nbsp;</P>
页: [1]
查看完整版本: 帮忙:查找错误,一个VBA中的数据库技术的程序。谢谢