Results 1 to 4 of 4
  1. #1
    fucell26 is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Jun 2014
    Location
    Saudi Arabia
    Posts
    11

    Conditional Statement

    guys i have this code


    Code:
    DoCmd.OpenReport "MainReport", acViewPreview, , RCriteria
    now my problem is what if the MainReport is open. i dont the exact syntax of conditional statement if the report is open.

    its like if the vba finds out that the report template is still open, there should be a message like Msgbox " please close the report first"

    thanks..

    fucell

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Can't user see that the report is still open? Why would they try to open it again?

    Try:

    If CurrentProject.AllReports("report name").IsLoaded Then
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    fucell26 is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Jun 2014
    Location
    Saudi Arabia
    Posts
    11
    actually what my macro doing is to query a table and then after query call a report template and then print. but the form is still open so that they can search a new query again. And usually the user forgot to close the report and when they are trying to generate a report again, program will not do anything because its open. that's why i need the conditional statement.

    Anyhow thank you and I will try your code.

    fucell

  4. #4
    Z1nkstar's Avatar
    Z1nkstar is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Mar 2014
    Location
    TX, USA
    Posts
    145
    Here is what I have found you said you wanted a msg box that says error you need to close report first well here are 2 different ways you can make a great msg box:
    1.This one is more less simple gives a statement and a yes or no feature
    Code:
    If MsgBox("This is What the MSGBOX will say!!!", vbQuestion + vbYesNo, "This is What you want it to do") = vbYes Then
    DoCmd.RunCommand 'Make Sure you run whatever Command you chose to do
    End If
    2.More advanced that has a 3 button layout same concept.
    Code:
    On Error GoTo Err_bSave_Click
    
    
        Me.tbHidden.SetFocus
    
    
        If IsNull(tbFirstName) Or IsNull(tbLastName) Then
            Beep
            MsgBox "All required fields must be completed before you can save a record.", vbCritical, "Invalid Save"
            Exit Sub
        End If
    
    
        Beep
        Select Case MsgBox("Do you want to save your changes to the current record?" & vbCrLf & vbLf & "  Yes:         Saves Changes" & vbCrLf & "  No:          Does NOT Save Changes" & vbCrLf & "  Cancel:    Reset (Undo) Changes" & vbCrLf, vbYesNoCancel + vbQuestion, "Save Current Record?")
            Case vbYes: 'Save the changes
                DoCmd.RunCommand acCmdSaveRecord
    
    
            Case vbNo: 'Do not save or undo
                'Do nothing
    
    
            Case vbCancel: 'Undo the changes
                DoCmd.RunCommand acCmdUndo
    
    
            Case Else: 'Default case to trap any errors
                'Do nothing
        End Select
    
    
    Exit_bSave_Click:
        Exit Sub
    
    
    Err_bSave_Click:
        If Err = 2046 Then 'The command or action Undo is not available now
            Exit Sub
        Else
            MsgBox Err.Number & " - " & Err.Description
            Resume Exit_bSave_Click
        End If

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 05-26-2013, 09:10 PM
  2. Insert Recordset with conditional statement
    By mjd973 in forum Programming
    Replies: 3
    Last Post: 04-29-2013, 06:20 AM
  3. Help with conditional statement in query
    By batowl in forum Queries
    Replies: 1
    Last Post: 08-23-2011, 02:00 PM
  4. Conditional Select Statement
    By shexe in forum Queries
    Replies: 4
    Last Post: 09-22-2010, 09:10 AM
  5. Help with Conditional statement in query
    By Rhues in forum Queries
    Replies: 1
    Last Post: 01-11-2010, 02:09 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums