A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Command Not Available Error Using Automation



 
 
Thread Tools Display Modes
  #1  
Old September 14th, 2009, 09:27 PM posted to microsoft.public.access.forms
AG[_3_]
external usenet poster
 
Posts: 129
Default Command Not Available Error Using Automation

Hi all,

I need to change the background color of all forms in an Access 2000
application using automation from another application.
The following works on most forms, but on some, I receive the error 2046 -
The command or action 'OpenForm' isn't available now.
The error occurs on the line appAccess.DoCmd.OpenForm strFrm, acDesign.
If I set the application to visible, I can break in the code and open the
form in design view manually, with no error.
I doubt it is a corruption issue, because I exported one of the offending
forms as text and re-imported it.

If I run similar code (not needing to createobject) from within the
application, it runs fine.

Does anyone have any ideas as to the cause (and solution) for the error?

Public Function StyleDestDb(ByVal strDestFile As String) As Boolean

Dim appAccess As Access.Application
Dim dbS As Access.CodeProject
Dim obJ As Access.AccessObject
Dim strFrm As String
Dim frM As Access.Form
Dim arObj() As String
Dim intCnt As Integer
Dim intIdx As Integer

On Error GoTo ErrLine
Set appAccess = CreateObject("Access.Application")
appAccess.OpenCurrentDatabase filePath:=strDestFile, Exclusive:=True
Set dbS = appAccess.CurrentProject
intCnt = dbS.AllForms.count
If intCnt 0 Then
ReDim arObj(intCnt - 1)
For Each obJ In dbS.AllForms
arObj(intIdx) = obJ.Name
intIdx = intIdx + 1
Next
Set obJ = Nothing
For intIdx = 0 To intCnt - 1
strFrm = arObj(intIdx)
appAccess.DoCmd.OpenForm strFrm, acDesign
DoEvents
Set frM = appAccess.Forms(strFrm)
frM.Section(acHeader).BackColor = conFormBackcolor
frM.Section(acDetail).BackColor = conFormBackcolor
frM.Section(acFooter).BackColor = conFormBackcolor
appAccess.DoCmd.Close acForm, strFrm, acSaveYes
DoEvents
Next
End If
StyleDestDb = True
ExitLine:
On Error Resume Next
Set frM = Nothing
Set obJ = Nothing
Set dbS = Nothing
appAccess.CloseCurrentDatabase
Set appAccess = Nothing
Exit Function

ErrLine:
If Err.Number = 2462 Then 'section number is invalid
Resume Next
Else
Call ReportError("StyleDestDb", strFrm) 'global error reporting
function
End If
Resume ExitLine
End Function

--

AG
Email: npATadhdataDOTcom




  #2  
Old September 15th, 2009, 07:26 AM posted to microsoft.public.access.forms
Charles Wang [MSFT]
external usenet poster
 
Posts: 68
Default Command Not Available Error Using Automation

Hi AG,
This is the known problem when the database window is hidden at the time
you call the OpenForm or OpenReport method from automation. You can refer
to this KB article to work around it.
BUG: Error Message 2046 Calling OpenForm or OpenReport with Access
Automation
http://support.microsoft.com/kb/244695

Hope this helps.

Best regards,
Charles Wang

  #3  
Old September 15th, 2009, 04:18 PM posted to microsoft.public.access.forms
AG[_3_]
external usenet poster
 
Posts: 129
Default Command Not Available Error Using Automation

That did it, thanks!

--

AG
Email: npATadhdataDOTcom


""Charles Wang [MSFT]"" wrote in message
...
Hi AG,
This is the known problem when the database window is hidden at the time
you call the OpenForm or OpenReport method from automation. You can refer
to this KB article to work around it.
BUG: Error Message 2046 Calling OpenForm or OpenReport with Access
Automation
http://support.microsoft.com/kb/244695

Hope this helps.

Best regards,
Charles Wang




 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 07:39 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.