By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,481 Members | 979 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,481 IT Pros & Developers. It's quick & easy.

Deleting Forms in other Database stops with error 2051

P: n/a
The following code is working In 97 but not in 2000
(start and finish are indicated by <<<<<<<<<<<< and >>>>>>>>>>>)
This action has to clean the specified database so, that delete all but
specified forms;
it is called from elsewhere by
call DelSaveFormsNew( dbfile, "f01",f02",...
In 97 this works as expected.
In 2000 deleting is not performed, when commeenting "on error" line in
deleteObject function and error 2501 is coming.
What could be reason for this.
<<<<<<<<<<<<<<<<<<<<<<<<<<<
Sub DelSaveFormsNew(DbFile As String, ParamArray FormsSaved() As Variant)
Dim intI As Integer

Dim dbs As Database, ctr As Container, doc As Document

' Returns reference to current database.
Set dbs = OpenDatabase(DbFile)
' Returns referenct to Forms container.
Set ctr = dbs.Containers!Forms
' Enumerates through Documents collection of Forms container.
For Each doc In ctr.Documents
' check if it is in array
For intI = LBound(FormsSaved()) To UBound(FormsSaved())
If doc.Name = FormsSaved(intI) Then
intI = 1000
End If
Next intI

If intI < 1000 Then
Debug.Print "to be deleted "; doc.Name
Debug.Print "DeleteObject(dbfile,acForm, doc.Name) = ";
DeleteObject(DbFile, acForm, doc.Name)

Else
Debug.Print "to be saved "; doc.Name; " intI=", intI
End If
Next doc
Set dbs = Nothing
End Sub
>>>>>>>>>>>>>>>>>>
<<<<<<<<<<<<<<<<<<<<<<<<
Public Function DeleteObject(Filename As String, _
objType As Integer, _
objName As String) As Boolean
On Error GoTo DeleteObject_Err
Dim accObj As New Access.Application
accObj.OpenCurrentDatabase Filename
accObj.DoCmd.DeleteObject objType, objName
accObj.CloseCurrentDatabase
Set accObj = Nothing
DeleteObject = True

DeleteObject_End:
Exit Function
DeleteObject_Err:

Resume DeleteObject_End
End Function
>>>>>>>>>>>>>>>>>>>>>>>>>>>

--
V.Moltchanov

Nov 12 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Vlasislav,

"Vladislav Moltchanov" <vl******************@ktl.fi> schrieb im
Newsbeitrag news:c8**********@oxygen.ktl.fi...
The following code is working In 97 but not in 2000
(start and finish are indicated by <<<<<<<<<<<< and >>>>>>>>>>>)
This action has to clean the specified database so, that delete all
but specified forms;
it is called from elsewhere by
call DelSaveFormsNew( dbfile, "f01",f02",...
In 97 this works as expected.
In 2000 deleting is not performed, when commeenting "on error" line
in
deleteObject function and error 2501 is coming.
What could be reason for this.


Did you check the references?

Use dao.database instead of database

Peter
Nov 13 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.