Unable to close Access application once CurrentDb() is used

F

Ferminus Stalin

I have created a ribbon control for Access 2007 using Visual Studio 2008
Shared Add-in under extensibility project type. I have assigned a user
defined function for one command button in the ribbon. This function is
working fine. When I try to close the applicatin after executing this
function atlease once, I am unable to do so. The file is getting closed, but
not the application. Below is the code I am using for the function.

Public Sub runTrim(ByVal control As IRibbonControl)
Dim i, n As Long
Dim db As Database, tbl As TableDef, fld As Field
Dim str, msgstr As String

If Not appAccess.CurrentObjectType = AcObjectType.acTable Then
Exit Sub
End If
Try

db = appAccess.CurrentDb()
tbl = db.TableDefs(appAccess.CurrentObjectName)
str = "UPDATE [" + tbl.Name + "] SET "

For Each fld In tbl.Fields
i = i + 1
If fld.Name <> "Sourceid" Then
Select Case i
Case 1
str = str + "[" + fld.Name + "]= trim([" +
fld.Name + "])"
Case Else
str = str + ", [" + fld.Name + "]= trim([" +
fld.Name + "])"
End Select
End If
Next fld

db.Execute(str, RecordsetOptionEnum.dbFailOnError)
n = db.RecordsAffected
msgstr = CStr(n) + " records on table '" + tbl.Name + "' trimmed
successfully"
MessageBox.Show(msgstr)


tbl = Nothing
db.Close()
db = Nothing

Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub


Unless I access the CurrentDb nothing is going wrong. Please help me to
solve this problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top