ajs Posted May 21, 2009 Share Posted May 21, 2009 Complete VBA rookie here: I was going through an autodesk tutorial on connecting to Access. Part of the tutorial is the following code: Public wksObj As Workspace Public dbsObj As Database Public tblObj As TableDef Public fldObj As Field Public rstObj As Recordset Private Sub CommandButton1_Click() On Error Resume Next Set wksObj = DBEngine.Workspaces(0) Set dbsObj = wksObj!CreateDatabase("mydbase.mdb", dbLangGeneral) Set tblObj = dbsObj!CreateTableDef("mytable") With tblObj .Fields.Append .CreateField("text", dbText) .Fields.Append .CreateField("integer", dbInteger) .Fields.Append .CreateField("long", dbLong) .Fields.Append .CreateField("double", dbDouble) .Fields.Append .CreateField("boolean", dbBoolean) .Fields.Append .CreateField("memo", dbMemo) .Fields.Append .CreateField("currency", dbCurrency) .Fields.Append .CreateField("date", dbDate) End With dbsObj.TableDefs.Append tblObj dbsObj.TableDefs.Refresh End Sub Private Sub CommandButton2_Click() On Error Resume Next Set dbsObj = DBEngine.Workspaces(0).OpenDatabase("mydbase.mdb") Set rstObj = dbsObj.OpenRecordset("mytable", dbOpenTable) rstObj.AddNew rstObj!Text = "a text value" rstObj!integer = 1 rstObj!double = 3.1415926 rstObj!Boolean = True rstObj!currency = "$4,240.54" rstObj!Date = "2/10/00" rstObj.Update rstObj.Close Set dbsObj = Nothing End Sub Private Sub CommandButton3_Click() Unload Me End Sub I'm getting a syntax error on the last code line for command button 2 (Highlighted in red bold) The error I'm getting is: Compile error / Syntax error. Can anyone enlighten me on what the syntax error is? I'm assuming that it has something to do with closing dbsObj and setting it to nil. Thanks... AJS Quote Link to comment Share on other sites More sharing options...
SEANT Posted May 21, 2009 Share Posted May 21, 2009 It may be as simple as: rstObj.Close Set dbsObj = Nothing in other words, put each statements on a separate line. Quote Link to comment Share on other sites More sharing options...
ajs Posted May 21, 2009 Author Share Posted May 21, 2009 That was it... Thank you Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.