Finding out if a report is in Design view or Print preview 
Author Message
 Finding out if a report is in Design view or Print preview

** I know I've posted this question in the Reports section also. It's was an
error I really wanted to post it in the DAO VBA section. My apologies. **

Hi everyone, here's one I would really appreciate if someone had the answer
to it. I made a little procedure that finds out if a table, a query or a
form is open in design view or in datasheet view (in the case of the form
it's in Form view). For this I use the ActiveDatasheet and ActiveForm's
CurrentView property, it works  uper. I can quickly find out that
information if it's a table, a query or a form. BUT (there's always a but,
right?) when it come to a report, I can't figure it out. The  eport object
doesn't have a CurrentView property. I've discover by the way that although
the Help file says that CurrentView applies only to Forms, it can also be
used against Table and Queries along with the ActiveDatasheet property.

But now I want to know the same thing about an open report. I know how to
use the CurrentObjectName and CurrentObjectType. Also I use the SysCmd to
find out if the object is at least open. I have everything I need to make
this little animal work EXCEPT for a report. Can anyone help, please!!

Note: It may be useful for you to know why I want to know this. I want to
make a function that will toggle any of the four Access object between
Design view and Run view (Datasheet view, Form View and Print preview). Then
attach this procedure to an AutoKeys macro where I assign, say, Ctrl+Q. I'm
tired (I'm sure I'm not alone) to constantly click the View button when I
develop an app. I've been successful to implement this with the first three
objects. Now the Reports is the last one.

If someone is able to help me with this, I promise I will make this
procedure available in the Users Group so that everybody can copy it and use
it immediately in their project. Somehow, I'm sure many beginners and
seasoned VBA programmers would like to have this.

Thanks very much for your help.

Daniel Lamarche



Fri, 30 May 2003 09:04:20 GMT  
 Finding out if a report is in Design view or Print preview
You can use the SysCmd Function to give you this information...

Steve

Quote:
> ** I know I've posted this question in the Reports section also. It's was
an
> error I really wanted to post it in the DAO VBA section. My apologies. **

> Hi everyone, here's one I would really appreciate if someone had the
answer
> to it. I made a little procedure that finds out if a table, a query or a
> form is open in design view or in datasheet view (in the case of the form
> it's in Form view).



Sat, 31 May 2003 02:46:19 GMT  
 Finding out if a report is in Design view or Print preview
Thank you Steve for your reply but (and I apologize for this) what you say
is not exact. The SysCmd will only tell me if an object is open or not. I
would have thought of this one. Actually I said in my post "Also I use the
SysCmd to find out if the object is at least open". The help specifies the
following about the SysCmd command along with the acSysCmdGetObjectState:

"An object can be in one of four possible states: not open or nonexistent,
open, new, or changed but not saved." That's what SysCmd can tell you. Not
if it's in Design view or Run view.

So, anybody else? I've found one solution to this by trying to read the Page
property from the report and generate an error it if the report is in Design
view. It works fine. Just wanted to know of anybody else had a more Access
VBA idea.

I would really appreciate the time you spend for this,

Daniel


Quote:
> You can use the SysCmd Function to give you this information...

> Steve


> > ** I know I've posted this question in the Reports section also. It's
was
> an
> > error I really wanted to post it in the DAO VBA section. My apologies.
**

> > Hi everyone, here's one I would really appreciate if someone had the
> answer
> > to it. I made a little procedure that finds out if a table, a query or a
> > form is open in design view or in datasheet view (in the case of the
form
> > it's in Form view).



Sat, 31 May 2003 07:52:51 GMT  
 Finding out if a report is in Design view or Print preview
You can do something klutzy!
First make sure the object is open. Then try to do something
programmatically to the object, that is only possible in design view. Then
catch the error and determine from there if it is open or closed.

Sorry it is the best I can come up with if you can't get to the view
property directly.

Pai Chung


Quote:
> Thank you Steve for your reply but (and I apologize for this) what you say
> is not exact. The SysCmd will only tell me if an object is open or not. I
> would have thought of this one. Actually I said in my post "Also I use the
> SysCmd to find out if the object is at least open". The help specifies the
> following about the SysCmd command along with the acSysCmdGetObjectState:

> "An object can be in one of four possible states: not open or nonexistent,
> open, new, or changed but not saved." That's what SysCmd can tell you. Not
> if it's in Design view or Run view.

> So, anybody else? I've found one solution to this by trying to read the
Page
> property from the report and generate an error it if the report is in
Design
> view. It works fine. Just wanted to know of anybody else had a more Access
> VBA idea.

> I would really appreciate the time you spend for this,

> Daniel



> > You can use the SysCmd Function to give you this information...

> > Steve


> > > ** I know I've posted this question in the Reports section also. It's
> was
> > an
> > > error I really wanted to post it in the DAO VBA section. My apologies.
> **

> > > Hi everyone, here's one I would really appreciate if someone had the
> > answer
> > > to it. I made a little procedure that finds out if a table, a query or
a
> > > form is open in design view or in datasheet view (in the case of the
> form
> > > it's in Form view).



Sun, 01 Jun 2003 01:07:42 GMT  
 Finding out if a report is in Design view or Print preview
Not 100% reliable (given the InStr), but here's another alternative.

' ********** Code Start *********
Private Declare Function apiFindWindowEx _
    Lib "user32" Alias "FindWindowExA" _
    (ByVal hWnd1 As Long, _
    ByVal hWnd2 As Long, _
    ByVal lpsz1 As String, _
    ByVal lpsz2 As String) _
    As Long

Private Declare Function apiGetClassName _
    Lib "user32" Alias "GetClassNameA" _
    (ByVal hWnd As Long, _
    ByVal lpClassname As String, _
    ByVal nMaxCount As Long) _
    As Long

Private Declare Function apiGetWindowText _
    Lib "user32" Alias "GetWindowTextA" _
    (ByVal hWnd As Long, _
    ByVal lpString As String, _
    ByVal aint As Long) _
    As Long

Private Const GW_CHILD = 5
Private Const GW_HWNDNEXT = 2
Private Const MAX_LEN = 255

Function fIsRptOpenInPrevMode( _
                strRptName As String) _
                As Boolean

Const WC_ACC_RPT_RT = "OPrtPrevPage"
Const WC_ACC_RPT = "OReport"
Const WC_ACC_MDI = "MDIClient"

Dim hWnd As Long

    hWnd = apiFindWindowEx( _
                    hWndAccessApp, _
                    0, _
                    WC_ACC_MDI, _
                    vbNullString)
    hWnd = apiFindWindowEx( _
                    hWnd, _
                    0, _
                    WC_ACC_RPT, _
                    vbNullString)
    ' Rpt can be maximized etc.
    If (InStr(1, Reports(strRptName).Name, _
                        fGetWndCaption(hWnd), _
                        vbTextCompare)) Then
        hWnd = apiFindWindowEx( _
                        hWnd, _
                        0, _
                        WC_ACC_RPT_RT, _
                        vbNullString)
        fIsRptOpenInPrevMode = CBool(hWnd)
    End If
End Function

Private Function fGetWndCaption(ByVal hWnd As Long) As String
Dim strBuffer As String
Dim lngRet As Long
  strBuffer = String$(MAX_LEN, 0)
  lngRet = apiGetWindowText(hWnd, strBuffer, Len(strBuffer))
  If lngRet > 0 Then
    fGetWndCaption = Left$(strBuffer, lngRet)
  End If
End Function
' ********** Code End ***********

  -- Dev



Sun, 01 Jun 2003 08:09:47 GMT  
 Finding out if a report is in Design view or Print preview

Whoops, just realized that you wanted to test _both_ design and
preview mode. A mminor tweak is required...

' ***** Code Start *******
Private Declare Function apiFindWindowEx _
    Lib "user32" Alias "FindWindowExA" _
    (ByVal hWnd1 As Long, _
    ByVal hWnd2 As Long, _
    ByVal lpsz1 As String, _
    ByVal lpsz2 As String) _
    As Long

Private Declare Function apiGetClassName _
    Lib "user32" Alias "GetClassNameA" _
    (ByVal hWnd As Long, _
    ByVal lpClassname As String, _
    ByVal nMaxCount As Long) _
    As Long

Private Declare Function apiGetWindowText _
    Lib "user32" Alias "GetWindowTextA" _
    (ByVal hWnd As Long, _
    ByVal lpString As String, _
    ByVal aint As Long) _
    As Long

Private Const GW_CHILD = 5
Private Const GW_HWNDNEXT = 2
Private Const MAX_LEN = 255

Function fIsReportOpen( _
                strRptName As String, _
                Optional blnTestPreviewMode As Boolean = True) _
                As Boolean

Const WC_ACC_RPT_RT = "OPrtPrevPage"
Const WC_ACC_RPT = "OReport"
Const WC_ACC_MDI = "MDIClient"

Dim hWnd As Long

    hWnd = apiFindWindowEx( _
                    hWndAccessApp, _
                    0, _
                    WC_ACC_MDI, _
                    vbNullString)
    hWnd = apiFindWindowEx( _
                    hWnd, _
                    0, _
                    WC_ACC_RPT, _
                    vbNullString)
    ' Rpt can be maximized etc.
    If (InStr(1, fGetWndCaption(hWnd), _
                    Reports(strRptName).Name, _
                    vbTextCompare)) Then
        hWnd = apiFindWindowEx( _
                        hWnd, _
                        0, _
                        WC_ACC_RPT_RT, _
                        vbNullString)
        fIsReportOpen = IIf(blnTestPreviewMode, _
                                    CBool(hWnd), _
                                    hWnd = 0)
    End If
End Function

Private Function fGetWndCaption(ByVal hWnd As Long) As String
Dim strBuffer As String
Dim lngRet As Long
  strBuffer = String$(MAX_LEN, 0)
  lngRet = apiGetWindowText(hWnd, strBuffer, Len(strBuffer))
  If lngRet > 0 Then
    fGetWndCaption = Left$(strBuffer, lngRet)
  End If
End Function
' ********Code End ********

  -- Dev



Sun, 01 Jun 2003 08:15:41 GMT  
 Finding out if a report is in Design view or Print preview
Hello Pai. Indeed that's what I had to do. I tried to get to the Page
property. If the report is in Design View, I can trap the error. Thanks for
the suggestion. It works fine with what you had in mind.
Daniel


Quote:
> You can do something klutzy!
> First make sure the object is open. Then try to do something
> programmatically to the object, that is only possible in design view. Then
> catch the error and determine from there if it is open or closed.

> Sorry it is the best I can come up with if you can't get to the view
> property directly.

> Pai Chung



> > Thank you Steve for your reply but (and I apologize for this) what you
say
> > is not exact. The SysCmd will only tell me if an object is open or not.
I
> > would have thought of this one. Actually I said in my post "Also I use
the
> > SysCmd to find out if the object is at least open". The help specifies
the
> > following about the SysCmd command along with the

acSysCmdGetObjectState:

- Show quoted text -

Quote:

> > "An object can be in one of four possible states: not open or
nonexistent,
> > open, new, or changed but not saved." That's what SysCmd can tell you.
Not
> > if it's in Design view or Run view.

> > So, anybody else? I've found one solution to this by trying to read the
> Page
> > property from the report and generate an error it if the report is in
> Design
> > view. It works fine. Just wanted to know of anybody else had a more
Access
> > VBA idea.

> > I would really appreciate the time you spend for this,

> > Daniel



> > > You can use the SysCmd Function to give you this information...

> > > Steve


> > > > ** I know I've posted this question in the Reports section also.
It's
> > was
> > > an
> > > > error I really wanted to post it in the DAO VBA section. My
apologies.
> > **

> > > > Hi everyone, here's one I would really appreciate if someone had the
> > > answer
> > > > to it. I made a little procedure that finds out if a table, a query
or
> a
> > > > form is open in design view or in datasheet view (in the case of the
> > form
> > > > it's in Form view).



Sun, 01 Jun 2003 09:28:38 GMT  
 Finding out if a report is in Design view or Print preview
Okayyyy! Dev. Wow, what a procedure. I don't know much about API calls but I
can recognize one when I see one. I copied and pasted the routine in my
module and it definitively return True or False depending of the state of a
report. Thanks very much for your hard work. It works fine.

Daniel Lamarche


Quote:
> Whoops, just realized that you wanted to test _both_ design and
> preview mode. A mminor tweak is required...

> ' ***** Code Start *******
> Private Declare Function apiFindWindowEx _
>     Lib "user32" Alias "FindWindowExA" _
>     (ByVal hWnd1 As Long, _
>     ByVal hWnd2 As Long, _
>     ByVal lpsz1 As String, _
>     ByVal lpsz2 As String) _
>     As Long

> Private Declare Function apiGetClassName _
>     Lib "user32" Alias "GetClassNameA" _
>     (ByVal hWnd As Long, _
>     ByVal lpClassname As String, _
>     ByVal nMaxCount As Long) _
>     As Long

> Private Declare Function apiGetWindowText _
>     Lib "user32" Alias "GetWindowTextA" _
>     (ByVal hWnd As Long, _
>     ByVal lpString As String, _
>     ByVal aint As Long) _
>     As Long

> Private Const GW_CHILD = 5
> Private Const GW_HWNDNEXT = 2
> Private Const MAX_LEN = 255

> Function fIsReportOpen( _
>                 strRptName As String, _
>                 Optional blnTestPreviewMode As Boolean = True) _
>                 As Boolean

> Const WC_ACC_RPT_RT = "OPrtPrevPage"
> Const WC_ACC_RPT = "OReport"
> Const WC_ACC_MDI = "MDIClient"

> Dim hWnd As Long

>     hWnd = apiFindWindowEx( _
>                     hWndAccessApp, _
>                     0, _
>                     WC_ACC_MDI, _
>                     vbNullString)
>     hWnd = apiFindWindowEx( _
>                     hWnd, _
>                     0, _
>                     WC_ACC_RPT, _
>                     vbNullString)
>     ' Rpt can be maximized etc.
>     If (InStr(1, fGetWndCaption(hWnd), _
>                     Reports(strRptName).Name, _
>                     vbTextCompare)) Then
>         hWnd = apiFindWindowEx( _
>                         hWnd, _
>                         0, _
>                         WC_ACC_RPT_RT, _
>                         vbNullString)
>         fIsReportOpen = IIf(blnTestPreviewMode, _
>                                     CBool(hWnd), _
>                                     hWnd = 0)
>     End If
> End Function

> Private Function fGetWndCaption(ByVal hWnd As Long) As String
> Dim strBuffer As String
> Dim lngRet As Long
>   strBuffer = String$(MAX_LEN, 0)
>   lngRet = apiGetWindowText(hWnd, strBuffer, Len(strBuffer))
>   If lngRet > 0 Then
>     fGetWndCaption = Left$(strBuffer, lngRet)
>   End If
> End Function
> ' ********Code End ********

>   -- Dev



Sun, 01 Jun 2003 09:32:45 GMT  
 Finding out if a report is in Design view or Print preview
Right, you could set a propery to itself and trap for errors...

On Tue, 12 Dec 2000 12:07:42 -0500, "Pai Chung"

Quote:

>You can do something klutzy!
>First make sure the object is open. Then try to do something
>programmatically to the object, that is only possible in design view. Then
>catch the error and determine from there if it is open or closed.

>Sorry it is the best I can come up with if you can't get to the view
>property directly.

>Pai Chung



Mon, 02 Jun 2003 20:41:17 GMT  
 Finding out if a report is in Design view or Print preview
Dev,

Very cool !

<snipping sound heard> <g>

Steve



Quote:
>Whoops, just realized that you wanted to test _both_ design and
>preview mode. A mminor tweak is required...

>' ***** Code Start *******
>Private Declare Function apiFindWindowEx _
>    Lib "user32" Alias "FindWindowExA" _
>    (ByVal hWnd1 As Long, _
>    ByVal hWnd2 As Long, _
>    ByVal lpsz1 As String, _
>    ByVal lpsz2 As String) _
>    As Long

>Private Declare Function apiGetClassName _
>    Lib "user32" Alias "GetClassNameA" _
>    (ByVal hWnd As Long, _
>    ByVal lpClassname As String, _
>    ByVal nMaxCount As Long) _
>    As Long

>Private Declare Function apiGetWindowText _
>    Lib "user32" Alias "GetWindowTextA" _
>    (ByVal hWnd As Long, _
>    ByVal lpString As String, _
>    ByVal aint As Long) _
>    As Long

>Private Const GW_CHILD = 5
>Private Const GW_HWNDNEXT = 2
>Private Const MAX_LEN = 255

>Function fIsReportOpen( _
>                strRptName As String, _
>                Optional blnTestPreviewMode As Boolean = True) _
>                As Boolean

>Const WC_ACC_RPT_RT = "OPrtPrevPage"
>Const WC_ACC_RPT = "OReport"
>Const WC_ACC_MDI = "MDIClient"

>Dim hWnd As Long

>    hWnd = apiFindWindowEx( _
>                    hWndAccessApp, _
>                    0, _
>                    WC_ACC_MDI, _
>                    vbNullString)
>    hWnd = apiFindWindowEx( _
>                    hWnd, _
>                    0, _
>                    WC_ACC_RPT, _
>                    vbNullString)
>    ' Rpt can be maximized etc.
>    If (InStr(1, fGetWndCaption(hWnd), _
>                    Reports(strRptName).Name, _
>                    vbTextCompare)) Then
>        hWnd = apiFindWindowEx( _
>                        hWnd, _
>                        0, _
>                        WC_ACC_RPT_RT, _
>                        vbNullString)
>        fIsReportOpen = IIf(blnTestPreviewMode, _
>                                    CBool(hWnd), _
>                                    hWnd = 0)
>    End If
>End Function

>Private Function fGetWndCaption(ByVal hWnd As Long) As String
>Dim strBuffer As String
>Dim lngRet As Long
>  strBuffer = String$(MAX_LEN, 0)
>  lngRet = apiGetWindowText(hWnd, strBuffer, Len(strBuffer))
>  If lngRet > 0 Then
>    fGetWndCaption = Left$(strBuffer, lngRet)
>  End If
>End Function
>' ********Code End ********

>  -- Dev



Mon, 02 Jun 2003 20:42:09 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. changing between design and print preview views in vb code

2. Printing Access reports or using Access to print/preview reports

3. How to determine report mode (design or preview)?

4. disable print to file in print preview using Crystal Reports 4.6

5. Crystal Report: print preview and print

6. How to design print preview?

7. HELP: GPF viewing Crystal print preview

8. HELP: GPF viewing Crystal print preview

9. HELP: GPF viewing Crystal print preview

10. View Report Preview

11. ! Reports can be previewed but not viewed on Web

12. VB6 / Access - Error 2202 (No Printer Installed) When Opening Report in Design View

 

 
Powered by phpBB® Forum Software